关于RecyclerView
如何使用正确notifyItemRemoved
,有一些坑必须要填,直接调用
data.remove(posiiton);
notifyItemRemoved(position);
position的位置回错乱, onBindViewHolder
不会调用,所以必须加上notifyItemRangeChanged
才行
public void removeItem(int position){
data.remove(posiiton);
notifyItemRemoved(position);
notifyItemRangeChanged(position, data.size() - position);
}
@Override
public void onStart() {
super.onStart();
Window window = getDialog().getWindow();
WindowManager.LayoutParams windowParams = window.getAttributes();
windowParams.dimAmount = 0.0f;
windowParams.flags |= WindowManager.LayoutParams.FLAG_DIM_BEHIND;
window.setAttributes(windowParams);
}
这里有个比较详尽的测试demo,测试了几个刷新的notify,可做参考。
RecyclerView正确使用notify(notifyItemRemoved,notifyItemChanged,notifyItemRemoved,notifyItemInserte...