The Android Developer Challenge is back! Submit your idea before December 2.

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

abstract Any!
get(position: Int)

Returns the item for the given position.

open Long
getId(position: Int)

Returns the id for the given position.

Presenter!
getPresenter(item: Any!)

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.

open Boolean

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

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

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.

abstract Int

Returns the number of items in the adapter.

Unit

Unregisters all DataObservers for this ObjectAdapter.

Unit

Unregisters a DataObserver for data change notifications.

Protected methods

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

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.

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

get

abstract fun get(position: Int): Any!

Returns the item for the given position.

getId

open fun getId(position: Int): Long

Returns the id for the given position.

getPresenter

fun getPresenter(item: Any!): Presenter!

Returns the Presenter for the given item from the adapter.

getPresenterSelector

fun getPresenterSelector(): PresenterSelector!

Returns the presenter selector for this ObjectAdapter.

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.

isImmediateNotifySupported

open fun isImmediateNotifySupported(): Boolean

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

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.

registerObserver

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

Registers a DataObserver for data change notifications.

setHasStableIds

fun setHasStableIds(hasStableIds: Boolean): Unit

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

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.

unregisterAllObservers

fun unregisterAllObservers(): Unit

Unregisters all DataObservers for this ObjectAdapter.

unregisterObserver

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

Unregisters a DataObserver for data change notifications.

Protected methods

notifyChanged

protected fun notifyChanged(): Unit

Notifies UI that the underlying data has changed.

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.

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.

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.

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.