SparseArrayObjectAdapter

class SparseArrayObjectAdapter : 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 functions

Unit

Removes all items from this adapter, leaving it empty.

Unit
clear(key: Int)

Clears the given key and associated item from the adapter.

Any?
get(position: Int)

Returns the item for the given position.

Int
indexOf(item: Any!)

Returns the index for the given item in the adapter.

Int
indexOf(key: Int)

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.

Any!
lookup(key: Int)

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

Unit
notifyArrayItemRangeChanged(positionStart: Int, itemCount: Int)

Notify that the content of a range of items changed.

Unit
set(key: Int, item: Any!)

Sets the item for the given key.

Int

Returns the number of items in the adapter.

Inherited Constants

From androidx.leanback.widget.ObjectAdapter
const Int
NO_ID = -1

Indicates that an id has not been set.

Inherited functions

From androidx.leanback.widget.ObjectAdapter
Long
getId(position: Int)

Returns the id for the given position.

Presenter?

Returns the Presenter for the given item from the adapter.

PresenterSelector

Returns the presenter selector for this ObjectAdapter.

Boolean

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

Unit

Notifies UI that the underlying data has changed.

Unit
notifyItemMoved(fromPosition: Int, toPosition: Int)

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

Unit
notifyItemRangeChanged(positionStart: Int, itemCount: Int)

Notifies UI that some items has changed.

Unit
notifyItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?)

Notifies UI that some items has changed.

Unit
notifyItemRangeInserted(positionStart: Int, itemCount: Int)

Notifies UI that new items has been inserted.

Unit
notifyItemRangeRemoved(positionStart: Int, itemCount: Int)

Notifies UI that some items that has been removed.

Unit

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

Unit

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

Unit

Registers a DataObserver for data change notifications.

Unit
setHasStableIds(hasStableIds: Boolean)

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

Unit

Sets the presenter selector.

Unit

Unregisters all DataObservers for this ObjectAdapter.

Unit

Unregisters a DataObserver for data change notifications.

Public constructors

SparseArrayObjectAdapter

Added in 1.1.0
SparseArrayObjectAdapter()

Constructs an adapter.

SparseArrayObjectAdapter

Added in 1.1.0
SparseArrayObjectAdapter(presenter: Presenter!)

Constructs an adapter with the given Presenter.

SparseArrayObjectAdapter

Added in 1.1.0
SparseArrayObjectAdapter(presenterSelector: PresenterSelector!)

Constructs an adapter with the given PresenterSelector.

Public functions

clear

Added in 1.1.0
fun clear(): Unit

Removes all items from this adapter, leaving it empty.

clear

Added in 1.1.0
fun clear(key: Int): Unit

Clears the given key and associated item from the adapter.

Parameters
key: Int

The key to be cleared.

get

Added in 1.2.0-alpha04
fun get(position: Int): Any?

Returns the item for the given position.

indexOf

Added in 1.1.0
fun indexOf(item: Any!): Int

Returns the index for the given item in the adapter.

Parameters
item: Any!

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
fun indexOf(key: Int): Int

Returns the index for the given key in the adapter.

Parameters
key: Int

The key to find in the array.

Returns
Int

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

isImmediateNotifySupported

fun isImmediateNotifySupported(): Boolean

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

lookup

Added in 1.1.0
fun lookup(key: Int): Any!

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

notifyArrayItemRangeChanged

Added in 1.1.0
fun notifyArrayItemRangeChanged(positionStart: Int, itemCount: Int): Unit

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

Parameters
positionStart: Int

The position of first item that has changed.

itemCount: Int

The count of how many items have changed.

set

Added in 1.1.0
fun set(key: Int, item: Any!): Unit

Sets the item for the given key.

Parameters
key: Int

The key associated with the item.

item: Any!

The item associated with the key.

size

Added in 1.2.0-alpha04
fun size(): Int

Returns the number of items in the adapter.