public class SortedList
extends Object

   ↳ androidx.recyclerview.widget.SortedList<T>

A Sorted list implementation that can keep items in order and also notify for changes in the list such that it can be bound to a RecyclerView.Adapter.

It keeps items ordered using the, Object) method and uses binary search to retrieve items. If the sorting criteria of your items may change, make sure you call appropriate methods while editing them to avoid data inconsistencies.

You can control the order of items and change notifications via the SortedList.Callback parameter.


Nested classes

class SortedList.BatchedCallback<T2>

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

class SortedList.Callback<T2>

The class that controls the behavior of the SortedList



Used by indexOf(Object) when the item cannot be found in the list.

Public constructors

SortedList(Class<T> klass, Callback<T> callback)

Creates a new SortedList of type T.

SortedList(Class<T> klass, Callback<T> callback, int initialCapacity)

Creates a new SortedList of type T.

Public methods

int add(T item)

Adds the given item to the list.

void addAll(T... items)

Adds the given items to the list.

void addAll(Collection<T> items)

Adds the given items to the list.

void addAll(T[] items, boolean mayModifyInput)

Adds the given items to the list.

void beginBatchedUpdates()

Batches adapter updates that happen after calling this method and before calling endBatchedUpdates().

void clear()

Removes all items from the SortedList.

void endBatchedUpdates()

Ends the update transaction and dispatches any remaining event to the callback.

T get(int index)

Returns the item at the given index.

int indexOf(T item)

Returns the position of the provided item.