java.lang.IndexOutOfBoundsException: Invalid index 10, size is 8
在绑定点击事件时一定要用holder.getAdapterPosition()
因为自己的绑定事件写在了onBindViewHolder里,而用了此方法的position,所以数据刷新时报错。删除时通知:
for (int i = 0; i < itemCount; i++) {
mList.remove(pos);
}
notifyItemRangeRemoved(pos, itemCount);
notifyItemRangeChanged(pos, mList.size() - pos);
- 避免重复绑定事件:
if (holder.itemView.hasOnClickListeners()) {
return;
}
...
- 至于为什么要写在onBindViewHolder里,是因为如果写在Holder里,需要传N多参数…