why payloads in RecyclerView' onBindViewHolder is a list?

Werb :
 public void onBindViewHolder(VH holder, int position, List<Object> payloads) {
        onBindViewHolder(holder, position);
 }

I know when we want to update some view not all in RecyclerView item, i can use

public final void notifyItemChanged(int position, Object payload) {
        mObservable.notifyItemRangeChanged(position, 1, payload);
}

As that code see, the param is a object, but why in Adapter it change to list, and i must use list.get(0) to find my payload ?

Thanks

user1032613 :

From Android Docs:

Partial bind vs full bind:

The payloads parameter is a merge list from notifyItemChanged(int, Object) or notifyItemRangeChanged(int, int, Object). If the payloads list is not empty, the ViewHolder is currently bound to old data and Adapter may run an efficient partial update using the payload info. If the payload is empty, Adapter must run a full bind. Adapter should not assume that the payload passed in notify methods will be received by onBindViewHolder(). For example when the view is not attached to the screen, the payload in notifyItemChange() will be simply dropped.

It's a list because it's a merge list. You could have potentially called notifyItemChanged multiple times before the view is updated, each time with a potentially different payload.

For example, at the same time, multiple threads could simultaneously request an item update with payloads "fav count update" and "icon change" and "time stamp update". So it's not wise to assume your payload is the 0th item.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=439025&siteId=1