ArrayObjectAdapter


class ArrayObjectAdapter : ObjectAdapter


An ObjectAdapter implemented with an ArrayList.

Summary

Public constructors

Constructs an adapter.

Constructs an adapter that uses the given Presenter for all items.

Constructs an adapter with the given PresenterSelector.

Public functions

Unit
add(item: Any)

Adds an item to the end of the adapter.

Unit
add(index: Int, item: Any)

Inserts an item into this adapter at the specified index.

Unit
addAll(index: Int, items: (Mutable)Collection<Any!>)

Adds the objects in the given collection to the adapter, starting at the given index.

Unit

Removes all items from this adapter, leaving it empty.

Any?
get(index: Int)

Returns the item for the given position.

Int
indexOf(item: Any)

Returns the index for the first occurrence of item in the adapter, or -1 if not found.

Boolean

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

Unit
move(fromPosition: Int, toPosition: Int)

Moved the item at fromPosition to toPosition.

Unit
notifyArrayItemRangeChanged(positionStart: Int, itemCount: Int)

Notify that the content of a range of items changed.

Boolean
remove(item: Any)

Removes the first occurrence of the given item from the adapter.

Int
removeItems(position: Int, count: Int)

Removes a range of items from the adapter.

Unit
replace(position: Int, item: Any)

Replaces item at position with a new item and calls notifyItemRangeChanged() at the given position.

Unit
setItems(itemList: (Mutable)List, callback: DiffCallback?)

Set a new item list to adapter.

Int

Returns the number of items in the adapter.

(Mutable)List<E!>

Gets a read-only view of the list of object of this ArrayObjectAdapter.

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

ArrayObjectAdapter

Added in 1.1.0
ArrayObjectAdapter()

Constructs an adapter.

ArrayObjectAdapter

Added in 1.1.0
ArrayObjectAdapter(presenter: Presenter)

Constructs an adapter that uses the given Presenter for all items.

ArrayObjectAdapter

Added in 1.1.0
ArrayObjectAdapter(presenterSelector: PresenterSelector)

Constructs an adapter with the given PresenterSelector.

Public functions

add

Added in 1.1.0
fun add(item: Any): Unit

Adds an item to the end of the adapter.

Parameters
item: Any

The item to add to the end of the adapter.

add

Added in 1.1.0
fun add(index: Int, item: Any): Unit

Inserts an item into this adapter at the specified index. If the index is >size an exception will be thrown.

Parameters
index: Int

The index at which the item should be inserted.

item: Any

The item to insert into the adapter.

addAll

Added in 1.2.0-alpha04
fun addAll(index: Int, items: (Mutable)Collection<Any!>): Unit

Adds the objects in the given collection to the adapter, starting at the given index. If the index is >= size an exception will be thrown.

Parameters
index: Int

The index at which the items should be inserted.

items: (Mutable)Collection<Any!>

A Collection of items to insert.

clear

Added in 1.1.0
fun clear(): Unit

Removes all items from this adapter, leaving it empty.

get

Added in 1.2.0-alpha04
fun get(index: 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 first occurrence of item in the adapter, or -1 if not found.

Parameters
item: Any

The item to find in the list.

Returns
Int

Index of the first occurrence of the item in the adapter, or -1 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.

move

Added in 1.1.0
fun move(fromPosition: Int, toPosition: Int): Unit

Moved the item at fromPosition to toPosition.

Parameters
fromPosition: Int

Previous position of the item.

toPosition: Int

New position of the item.

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.

remove

Added in 1.1.0
fun remove(item: Any): Boolean

Removes the first occurrence of the given item from the adapter.

Parameters
item: Any

The item to remove from the adapter.

Returns
Boolean

True if the item was found and thus removed from the adapter.

removeItems

Added in 1.1.0
fun removeItems(position: Int, count: Int): Int

Removes a range of items from the adapter. The range is specified by giving the starting position and the number of elements to remove.

Parameters
position: Int

The index of the first item to remove.

count: Int

The number of items to remove.

Returns
Int

The number of items removed.

replace

Added in 1.1.0
fun replace(position: Int, item: Any): Unit

Replaces item at position with a new item and calls notifyItemRangeChanged() at the given position. Note that this method does not compare new item to existing item.

Parameters
position: Int

The index of item to replace.

item: Any

The new item to be placed at given position.

setItems

Added in 1.1.0
fun setItems(itemList: (Mutable)List, callback: DiffCallback?): Unit

Set a new item list to adapter. The DiffUtil will compute the difference and dispatch it to specified position.

Parameters
itemList: (Mutable)List

List of new Items

callback: DiffCallback?

Optional DiffCallback Object to compute the difference between the old data set and new data set. When null, notifyChanged will be fired.

size

Added in 1.2.0-alpha04
fun size(): Int

Returns the number of items in the adapter.

unmodifiableList

Added in 1.1.0
fun <E> unmodifiableList(): (Mutable)List<E!>

Gets a read-only view of the list of object of this ArrayObjectAdapter.