public class

SortedList.BatchedCallback<T2>

extends SortedList.Callback<java.lang.Object>

 java.lang.Object

androidx.recyclerview.widget.SortedList.Callback<java.lang.Object>

↳androidx.recyclerview.widget.SortedList.BatchedCallback<T2>

Overview

A callback implementation that can batch notify events dispatched by the SortedList.

This class can be useful if you want to do multiple operations on a SortedList but don't want to dispatch each event one by one, which may result in a performance issue.

For example, if you are going to add multiple items to a SortedList, BatchedCallback call convert individual onInserted(index, 1) calls into one onInserted(index, N) if items are added into consecutive indices. This change can help RecyclerView resolve changes much more easily.

If consecutive changes in the SortedList are not suitable for batching, BatchingCallback dispatches them as soon as such case is detected. After your edits on the SortedList is complete, you must always call SortedList.BatchedCallback.dispatchLastEvent() to flush all changes to the Callback.

Summary

Constructors
publicBatchedCallback(SortedList.Callback<java.lang.Object> wrappedCallback)

Creates a new BatchedCallback that wraps the provided Callback.

Methods
public booleanareContentsTheSame(java.lang.Object oldItem, java.lang.Object newItem)

public booleanareItemsTheSame(java.lang.Object item1, java.lang.Object item2)

public intcompare(java.lang.Object o1, java.lang.Object o2)

public voiddispatchLastEvent()

This method dispatches any pending event notifications to the wrapped Callback.

public java.lang.ObjectgetChangePayload(java.lang.Object item1, java.lang.Object item2)

public voidonChanged(int position, int count)

public voidonChanged(int position, int count, java.lang.Object payload)

public voidonInserted(int position, int count)

public voidonMoved(int fromPosition, int toPosition)

public voidonRemoved(int position, int count)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public BatchedCallback(SortedList.Callback<java.lang.Object> wrappedCallback)

Creates a new BatchedCallback that wraps the provided Callback.

Parameters:

wrappedCallback: The Callback which should received the data change callbacks. Other method calls (e.g. SortedList.BatchedCallback.compare(T2, T2) from the SortedList are directly forwarded to this Callback.

Methods

public int compare(java.lang.Object o1, java.lang.Object o2)

public void onInserted(int position, int count)

public void onRemoved(int position, int count)

public void onMoved(int fromPosition, int toPosition)

public void onChanged(int position, int count)

public void onChanged(int position, int count, java.lang.Object payload)

public boolean areContentsTheSame(java.lang.Object oldItem, java.lang.Object newItem)

public boolean areItemsTheSame(java.lang.Object item1, java.lang.Object item2)

public java.lang.Object getChangePayload(java.lang.Object item1, java.lang.Object item2)

public void dispatchLastEvent()

This method dispatches any pending event notifications to the wrapped Callback. You must always call this method after you are done with editing the SortedList.