ObjectAdapter
public abstract class ObjectAdapter
ArrayObjectAdapter |
An |
CursorObjectAdapter |
An |
PagingDataAdapter |
An |
SparseArrayObjectAdapter |
An |
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 types |
|---|
public abstract class ObjectAdapter.DataObserverA DataObserver can be notified when an ObjectAdapter's underlying data changes. |
Constants |
|
|---|---|
static final int |
NO_ID = -1Indicates that an id has not been set. |
Public constructors |
|---|
|
Constructs an adapter. |
ObjectAdapter(@NonNull Presenter presenter)Constructs an adapter that uses the given |
ObjectAdapter(@NonNull PresenterSelector presenterSelector)Constructs an adapter with the given |
Public methods |
|
|---|---|
abstract @Nullable Object |
get(int position)Returns the item for the given position. |
long |
getId(int position)Returns the id for the given position. |
final @Nullable Presenter |
getPresenter(@NonNull Object item)Returns the |
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. |
boolean |
Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise. |
final void |
notifyItemRangeChanged(int positionStart, int itemCount)Notifies UI that some items has changed. |
final void |
notifyItemRangeChanged(Notifies UI that some items has changed. |
final void |
registerObserver(@NonNull ObjectAdapter.DataObserver observer)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 |
setPresenterSelector(@NonNull PresenterSelector presenterSelector)Sets the presenter selector. |
abstract int |
size()Returns the number of items in the adapter. |
final void |
Unregisters all DataObservers for this ObjectAdapter. |
final void |
unregisterObserver(@NonNull ObjectAdapter.DataObserver observer)Unregisters a DataObserver for data change notifications. |
Protected methods |
|
|---|---|
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 |
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 |
void |
Called when |
Constants
Public constructors
ObjectAdapter
public ObjectAdapter(@NonNull Presenter presenter)
Constructs an adapter that uses the given Presenter for all items.
ObjectAdapter
public ObjectAdapter(@NonNull PresenterSelector presenterSelector)
Constructs an adapter with the given PresenterSelector.
Public methods
get
public abstract @Nullable Object get(int position)
Returns the item for the given position.
getPresenter
public final @Nullable Presenter getPresenter(@NonNull Object item)
Returns the Presenter for the given item from the adapter.
getPresenterSelector
public final @NonNull PresenterSelector getPresenterSelector()
Returns the presenter selector for this ObjectAdapter.
hasStableIds
public final boolean hasStableIds()
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 to correlate Objects across changes.
isImmediateNotifySupported
public boolean isImmediateNotifySupported()
Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise.
notifyItemRangeChanged
public final void notifyItemRangeChanged(int positionStart, int itemCount)
Notifies UI that some items has changed.
| Parameters | |
|---|---|
int positionStart |
Starting position of the changed items. |
int itemCount |
Total number of items that changed. |
notifyItemRangeChanged
public final void notifyItemRangeChanged(
int positionStart,
int itemCount,
@Nullable Object payload
)
Notifies UI that some items has changed.
registerObserver
public final void registerObserver(@NonNull ObjectAdapter.DataObserver observer)
Registers a DataObserver for data change notifications.
setHasStableIds
public final void setHasStableIds(boolean hasStableIds)
Sets whether the item ids are stable across changes to the underlying data.
setPresenterSelector
public final void setPresenterSelector(@NonNull PresenterSelector presenterSelector)
Sets the presenter selector. May not be null.
unregisterAllObservers
public final void unregisterAllObservers()
Unregisters all DataObservers for this ObjectAdapter.
unregisterObserver
public final void unregisterObserver(@NonNull ObjectAdapter.DataObserver observer)
Unregisters a DataObserver for data change notifications.
Protected methods
notifyChanged
protected final void notifyChanged()
Notifies UI that the underlying data has changed.
notifyItemMoved
protected final void notifyItemMoved(int fromPosition, int toPosition)
Notifies UI that item at fromPosition has been moved to toPosition.
| Parameters | |
|---|---|
int fromPosition |
Previous position of the item. |
int toPosition |
New position of the item. |
notifyItemRangeInserted
protected final void notifyItemRangeInserted(int positionStart, int itemCount)
Notifies UI that new items has been inserted.
| Parameters | |
|---|---|
int positionStart |
Position where new items has been inserted. |
int itemCount |
Count of the new items has been inserted. |
notifyItemRangeRemoved
protected final void notifyItemRangeRemoved(int positionStart, int itemCount)
Notifies UI that some items that has been removed.
| Parameters | |
|---|---|
int positionStart |
Starting position of the removed items. |
int itemCount |
Total number of items that has been removed. |
onHasStableIdsChanged
protected void onHasStableIdsChanged()
Called when setHasStableIds is called and the status of stable ids has changed.
onPresenterSelectorChanged
protected void onPresenterSelectorChanged()
Called when setPresenterSelector is called and the PresenterSelector differs from the previous one.