gpt4 book ai didi

Android RecyclerView notifyItemRangeChanged 与 notifyItemChanged

转载 作者:太空狗 更新时间:2023-10-29 16:01:56 27 4
gpt4 key购买 nike

我有一个数据集,它可能会在刷新时发生变化。很难确定现有数据集中的哪些条目已更改。我通读了 recyclerview 适配器说明,我的主要问题是。

确定更改了哪个数据 View ,然后对受影响的范围使用 notifyItemRangeChanged 是否更有效,还是我应该一个一个地更改它们,然后在每个数据 View 更改后使用 notifyItemChanged?

它变得稍微复杂一些,因为根据更改的内容,每个 View 的顺序可能已经更改,那么它是调用 notifyItemRangeInserted 的参数,为受影响的范围调用 notifyItemRangeRemoved,还是一个一个地调用 notifyItemMoved?

哪种方式更有效?

谢谢

最佳答案

这是源代码,v7-22.1.1

    /**
* Notify any registered observers that the item at <code>position</code> has changed.
*
* <p>This is an item change event, not a structural change event. It indicates that any
* reflection of the data at <code>position</code> is out of date and should be updated.
* The item at <code>position</code> retains the same identity.</p>
*
* @param position Position of the item that has changed
*
* @see #notifyItemRangeChanged(int, int)
*/
public final void notifyItemChanged(int position) {
mObservable.notifyItemRangeChanged(position, 1);
}

/**
* Notify any registered observers that the <code>itemCount</code> items starting at
* position <code>positionStart</code> have changed.
*
* <p>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.</p>
*
* @param positionStart Position of the first item that has changed
* @param itemCount Number of items that have changed
*
* @see #notifyItemChanged(int)
*/
public final void notifyItemRangeChanged(int positionStart, int itemCount) {
mObservable.notifyItemRangeChanged(positionStart, itemCount);
}

所以,notifyItemChanged(int) notifyItemRangeChanged(int, int)

关于Android RecyclerView notifyItemRangeChanged 与 notifyItemChanged,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28743254/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com