天天看點

小知識 - notifyItemRemoved導緻的數組下标越界問題

我們一般在RecyclerView清單中移除某條Item時會調用 notifyItemRemoved 方法,其還附帶了相應的移除動畫。使用雖然簡單,卻埋了一個大坑;

說了這麼多,解決辦法呢?

val list=xxxx
val postition=1
//例如移除位置position=1
notifyItemRemoved(position)
notifyItemRangeChanged(position,list.size-position)

      

notifyItemRangeChanged 方法是幹啥的呢?