added in version 22.1.0
belongs to Maven artifact


public static class SortedList.BatchedCallback
extends Callback<T2>


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 dispatchLastEvent() to flush all changes to the Callback.


Public constructors

SortedList.BatchedCallback(Callback<T2> wrappedCallback)

Creates a new BatchedCallback that wraps the provided Callback.

Public methods

boolean areContentsTheSame(T2 oldItem, T2 newItem)

Called by the SortedList when it wants to check whether two items have the same data or not.

boolean areItemsTheSame(T2 item1, T2 item2)

Called by the SortedList to decide whether two objects represent the same Item or not.

int compare(T2 o1, T2 o2)

Similar to compare(Object, Object), should compare two and return how they should be ordered.

void dispatchLastEvent()

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

Object getChangePayload(T2 item1, T2 item2)

When areItemsTheSame(T2, T2) returns true for two items and areContentsTheSame(T2, T2) returns false for them, SortedList.Callback calls this method to get a payload about the change.

void onChanged(int position, int count, Object payload)

Called when count number of items are updated at the given position.

void onChanged(int position, int count)

Called by the SortedList when the item at the given position is updated.

void onInserted(int position, int count)
void onMoved(int fromPosition, int toPosition)
void onRemoved(int position, int count)

Inherited methods

From class