ObjectAdapter

abstract class ObjectAdapter
kotlin.Any
   ↳ androidx.leanback.widget.ObjectAdapter

Base class adapter to be used in leanback activities. Provides access to a data model and is decoupled from the presentation of the items via PresenterSelector.

Summary

Nested classes
abstract

A DataObserver can be notified when an ObjectAdapter's underlying data changes.

Constants
static Int

Indicates that an id has not been set.

Public constructors
<init>(presenterSelector: PresenterSelector!)

Constructs an adapter with the given PresenterSelector.

<init>(presenter: Presenter!)

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

Constructs an adapter.

Public methods
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.

open Long
getId(position: Int)

Returns the id for the given position.

Unit

Registers a DataObserver for data change notifications.

open Boolean

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

Unit

Unregisters all DataObservers for this ObjectAdapter.

Presenter!
getPresenter(item: Any!)

Returns the Presenter for the given item from the adapter.

Unit

Unregisters a DataObserver for data change notifications.

Boolean

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

PresenterSelector!

Returns the presenter selector for this ObjectAdapter.

Unit

Sets the presenter selector.

abstract Int

Returns the number of items in the adapter.

abstract Any!
get(position: Int)

Returns the item for the given position.

Unit
setHasStableIds(hasStableIds: Boolean)

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

Protected methods
Unit

Notifies UI that the underlying data has changed.

open Unit

Called when #setHasStableIds(boolean) is called and the status of stable ids has changed.

open Unit

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

Unit
notifyItemRangeRemoved(positionStart: Int, itemCount: Int)

Notifies UI that some items that has been removed.

Unit
notifyItemRangeInserted(positionStart: Int, itemCount: Int)

Notifies UI that new items has been inserted.

Unit
notifyItemMoved(fromPosition: Int, toPosition: Int)

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

Constants

NO_ID

static val NO_ID: Int

Indicates that an id has not been set.

Value: -1

Public constructors

<init>

ObjectAdapter(presenterSelector: PresenterSelector!)

Constructs an adapter with the given PresenterSelector.

<init>

ObjectAdapter(presenter: Presenter!)

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

<init>

ObjectAdapter()

Constructs an adapter.

Public methods

notifyItemRangeChanged

fun notifyItemRangeChanged(positionStart: Int, itemCount: Int): Unit

Notifies UI that some items has changed.

Parameters
positionStart Int: Starting position of the changed items.
itemCount Int: Total number of items that changed.

notifyItemRangeChanged

fun notifyItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any!): Unit

Notifies UI that some items has changed.

Parameters
positionStart Int: Starting position of the changed items.
itemCount Int: Total number of items that changed.
payload Int: Optional parameter, use null to identify a "full" update.

getId

open fun getId(position: Int): Long

Returns the id for the given position.

registerObserver

fun registerObserver(observer: ObjectAdapter.DataObserver!): Unit

Registers a DataObserver for data change notifications.

isImmediateNotifySupported

open fun isImmediateNotifySupported(): Boolean

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

unregisterAllObservers

fun unregisterAllObservers(): Unit

Unregisters all DataObservers for this ObjectAdapter.

getPresenter

fun getPresenter(item: Any!): Presenter!

Returns the Presenter for the given item from the adapter.

unregisterObserver

fun unregisterObserver(observer: ObjectAdapter.DataObserver!): Unit

Unregisters a DataObserver for data change notifications.

hasStableIds

fun hasStableIds(): Boolean

Returns true if the item ids are stable across changes to the underlying data. When this is true, clients of the ObjectAdapter can use #getId(int) to correlate Objects across changes.

getPresenterSelector

fun getPresenterSelector(): PresenterSelector!

Returns the presenter selector for this ObjectAdapter.

setPresenterSelector

fun setPresenterSelector(presenterSelector: PresenterSelector!): Unit

Sets the presenter selector. May not be null.

size

abstract fun size(): Int

Returns the number of items in the adapter.

get

abstract fun get(position: Int): Any!

Returns the item for the given position.

setHasStableIds

fun setHasStableIds(hasStableIds: Boolean): Unit

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

Protected methods

notifyChanged

protected fun notifyChanged(): Unit

Notifies UI that the underlying data has changed.

onHasStableIdsChanged

protected open fun onHasStableIdsChanged(): Unit

Called when #setHasStableIds(boolean) is called and the status of stable ids has changed.

onPresenterSelectorChanged

protected open fun onPresenterSelectorChanged(): Unit

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

notifyItemRangeRemoved

protected fun notifyItemRangeRemoved(positionStart: Int, itemCount: Int): Unit

Notifies UI that some items that has been removed.

Parameters
positionStart Int: Starting position of the removed items.
itemCount Int: Total number of items that has been removed.

notifyItemRangeInserted

protected fun notifyItemRangeInserted(positionStart: Int, itemCount: Int): Unit

Notifies UI that new items has been inserted.

Parameters
positionStart Int: Position where new items has been inserted.
itemCount Int: Count of the new items has been inserted.

notifyItemMoved

protected fun notifyItemMoved(fromPosition: Int, toPosition: Int): Unit

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

Parameters
fromPosition Int: Previous position of the item.
toPosition Int: New position of the item.