SparseArrayObjectAdapter


public class SparseArrayObjectAdapter extends ObjectAdapter


An ObjectAdapter implemented with a android.util.SparseArray. This class maintains an array of objects where each object is associated with an integer key which determines its order relative to other objects.

Summary

Public constructors

Constructs an adapter.

Constructs an adapter with the given Presenter.

Constructs an adapter with the given PresenterSelector.

Public methods

void

Removes all items from this adapter, leaving it empty.

void
clear(int key)

Clears the given key and associated item from the adapter.

@Nullable Object
get(int position)

Returns the item for the given position.

int

Returns the index for the given item in the adapter.

int
indexOf(int key)

Returns the index for the given key in the adapter.

boolean

Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise.

Object
lookup(int key)

Returns the object for the given key, or null if no mapping for that key exists.

void
notifyArrayItemRangeChanged(int positionStart, int itemCount)

Notify that the content of a range of items changed.

void
set(int key, Object item)

Sets the item for the given key.

int

Returns the number of items in the adapter.

Inherited Constants

From androidx.leanback.widget.ObjectAdapter
static final int
NO_ID = -1

Indicates that an id has not been set.

Inherited methods

From androidx.leanback.widget.ObjectAdapter
long
getId(int position)

Returns the id for the given position.

final @Nullable Presenter

Returns the Presenter for the given item from the adapter.

final @NonNull PresenterSelector

Returns the presenter selector for this ObjectAdapter.

final boolean

Returns true if the item ids are stable across changes to the underlying data.

final void

Notifies UI that the underlying data has changed.

final void
notifyItemMoved(int fromPosition, int toPosition)

Notifies UI that item at fromPosition has been moved to toPosition.

final void
notifyItemRangeChanged(int positionStart, int itemCount)

Notifies UI that some items has changed.

final void
notifyItemRangeChanged(
    int positionStart,
    int itemCount,
    @Nullable Object payload
)

Notifies UI that some items has changed.

final void
notifyItemRangeInserted(int positionStart, int itemCount)

Notifies UI that new items has been inserted.

final void
notifyItemRangeRemoved(int positionStart, int itemCount)

Notifies UI that some items that has been removed.

void

Called when setHasStableIds is called and the status of stable ids has changed.

void

Called when setPresenterSelector is called and the PresenterSelector differs from the previous one.

final void

Registers a DataObserver for data change notifications.

final void
setHasStableIds(boolean hasStableIds)

Sets whether the item ids are stable across changes to the underlying data.

final void

Sets the presenter selector.

final void

Unregisters all DataObservers for this ObjectAdapter.

final void

Unregisters a DataObserver for data change notifications.

Public constructors

SparseArrayObjectAdapter

Added in 1.1.0
public SparseArrayObjectAdapter()

Constructs an adapter.

SparseArrayObjectAdapter

Added in 1.1.0
public SparseArrayObjectAdapter(Presenter presenter)

Constructs an adapter with the given Presenter.

SparseArrayObjectAdapter

Added in 1.1.0
public SparseArrayObjectAdapter(PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

Public methods

clear

Added in 1.1.0
public void clear()

Removes all items from this adapter, leaving it empty.

clear

Added in 1.1.0
public void clear(int key)

Clears the given key and associated item from the adapter.

Parameters
int key

The key to be cleared.

get

Added in 1.2.0-alpha04
public @Nullable Object get(int position)

Returns the item for the given position.

indexOf

Added in 1.1.0
public int indexOf(Object item)

Returns the index for the given item in the adapter.

Parameters
Object item

The item to find in the array.

Returns
int

Index of the item, or a negative value if not found.

indexOf

Added in 1.1.0
public int indexOf(int key)

Returns the index for the given key in the adapter.

Parameters
int key

The key to find in the array.

Returns
int

Index of the item, or a negative value if not found.

isImmediateNotifySupported

public boolean isImmediateNotifySupported()

Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise.

lookup

Added in 1.1.0
public Object lookup(int key)

Returns the object for the given key, or null if no mapping for that key exists.

notifyArrayItemRangeChanged

Added in 1.1.0
public void notifyArrayItemRangeChanged(int positionStart, int itemCount)

Notify that the content of a range of items changed. Note that this is not same as items being added or removed.

Parameters
int positionStart

The position of first item that has changed.

int itemCount

The count of how many items have changed.

set

Added in 1.1.0
public void set(int key, Object item)

Sets the item for the given key.

Parameters
int key

The key associated with the item.

Object item

The item associated with the key.

size

Added in 1.2.0-alpha04
public int size()

Returns the number of items in the adapter.