notifyItemRemoved,notifyItemRangeRemoved和notifyItemRangeChanged(int positionStart, int itemCount, Ob

来源:互联网 发布:key-value数据库 编辑:程序博客网 时间:2024/06/08 05:19

1.public final void notifyItemRemoved(int position)
/**
* Notify any registered observers that the item previously located at position
* has been removed from the data set. The items previously located at and after
* position may now be found at oldPosition - 1.
*
*通知所有观察者之前在position位置的数据已经被remove
*

This is a structural change event. Representations of other existing items in the
* data set are still considered up to date and will not be rebound, though their positions
* may be altered.
* 这是一个结构性改变事件,其它还存在的数据的呈现依然被看成是最新的,虽然他们的position可能被更改了,但并不会被重新绑定

    public final void notifyItemRemoved(int position) {        mObservable.notifyItemRangeRemoved(position, 1);    }

2.public void notifyItemRangeRemoved(int positionStart, int itemCount)
public void notifyItemRangeRemoved(int positionStart, int itemCount) {
// since onItemRangeRemoved() is implemented by the app, it could do anything, including
// removing itself from {@link mObservers} - and that could cause problems if
// an iterator is used on the ArrayList {@link mObservers}.
// to avoid such problems, just march thru the list in the reverse order.
采用倒序
for (int i = mObservers.size() - 1; i >= 0; i–) {
mObservers.get(i).onItemRangeRemoved(positionStart, itemCount);
}
}
public final void notifyItemRangeChanged(int positionStart, int itemCount) {
mObservable.notifyItemRangeChanged(positionStart, itemCount);
}
3. public final void notifyItemRangeChanged(int positionStart, int itemCount, Object payload)
/**
* Notify any registered observers that the itemCount items starting at
* position positionStart have changed. An optional payload can be
* passed to each changed item.
*
*

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.
*


*
*


* Client can optionally pass a payload for partial change. These payloads will be merged
* and may be passed to adapter’s {@link #onBindViewHolder(ViewHolder, int, List)} if the
* item is already represented by a ViewHolder and it will be rebound to the same
* ViewHolder. A notifyItemRangeChanged() with null payload will clear all existing
* payloads on that item and prevent future payload until

     * {@link #onBindViewHolder(ViewHolder, int, List)} is called. Adapter should not assume     * that the payload will always be passed to onBindViewHolder(), e.g. when the view is not     * attached, the payload will be simply dropped.     *         * 如果item被ViewHolder呈现,那么这些数据会重新绑定到原来的ViewHolder上,如果payload为null,notifyItemRangeChanged()会被调用并且拒绝之后的payload直到onBindViewHolder(ViewHolder, int, List)被调用,适配器并不保证payload总是被传递到onBindViewHolder()方法,比如当View没有attach的时候,payload会被取消。     * @param positionStart Position of the first item that has changed     * @param itemCount Number of items that have changed     * @param payload  Optional parameter, use null to identify a "full" update     *     * @see #notifyItemChanged(int)     */    public final void notifyItemRangeChanged(int positionStart, int itemCount, Object payload) {        mObservable.notifyItemRangeChanged(positionStart, itemCount, payload);    }
0 0
原创粉丝点击