open class BatchedCallback<T2 : Any!> : SortedList.Callback<T2>
   ↳ androidx.recyclerview.widget.SortedList.Callback<T2>
   ↳ androidx.recyclerview.widget.SortedList.BatchedCallback

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


Public constructors

<init>(wrappedCallback: SortedList.Callback<T2>!)

Creates a new BatchedCallback that wraps the provided Callback.

Public methods

open Boolean
areContentsTheSame(oldItem: T2, newItem: T2)

open Boolean
areItemsTheSame(item1: T2, item2: T2)

open Int
compare(o1: T2, o2: T2)

open Unit

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

open Any?
getChangePayload(item1: T2, item2: T2)

open Unit
onChanged(position: Int, count: Int)

open Unit
onChanged(position: Int, count: Int, payload: Any?)

open Unit
onInserted(position: Int, count: Int)

open Unit
onMoved(fromPosition: Int, toPosition: Int)

open Unit
onRemoved(position: Int, count: Int)

Public constructors


BatchedCallback(wrappedCallback: SortedList.Callback<T2>!)

Creates a new BatchedCallback that wraps the provided Callback.

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

Public methods


open fun areContentsTheSame(oldItem: T2, newItem: T2): Boolean


open fun areItemsTheSame(item1: T2, item2: T2): Boolean


open fun compare(o1: T2, o2: T2): Int


open fun dispatchLastEvent(): Unit

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.


@Nullable open fun getChangePayload(item1: T2, item2: T2): Any?


open fun onChanged(position: Int, count: Int): Unit


open fun onChanged(position: Int, count: Int, payload: Any?): Unit


open fun onInserted(position: Int, count: Int): Unit


open fun onMoved(fromPosition: Int, toPosition: Int): Unit


open fun onRemoved(position: Int, count: Int): Unit