踩坑记录(1)-notifyItemRangeChanged

来源:互联网 发布:mac上的翻墙工具 编辑:程序博客网 时间:2024/06/01 13:23

在一个recyclerView 中,设置了滑动删除,和点击删除。点击删除没有问题,而滑动删除会出现显示的问题。
比如顺序的1—-2—-3—-4—-5。
滑动删掉4,再滑动删掉1,结果变为2—-空—-5。
实际3的数据还在,但是不显示,也没法交互。

其中删除的代码如下

//删除一条内容    private void deleteData(int position) {        int memoId = memoList.get(position).getId();        DBUtil.deleteMemo(memoId);        memoList.remove(position);        notifyItemRemoved(position);        notifyItemRangeChanged(position, memoList.size());    }

把notifyItemRangeChanged注释掉后,问题就解决了。so werid。

并不知道原因。。

相关的资料

public final void notifyItemRangeChanged (int positionStart, int itemCount)

Notify any registered observers that the itemCount items starting at
position positionStart have changed. Equivalent to calling
notifyItemRangeChanged(position, itemCount, null);.

This is an item change event, not a structural change event. It
indicates that any reflection of the data in the given position range
is out of date and should be updated. The items in the given range
retain the same identity.

Parameters
positionStart - -Position of the first item that has changed
itemCount - - Number of items that have changed

0 0