Stay organized with collections Save and categorize content based on your preferences.

CursorObjectAdapter

public class CursorObjectAdapter extends ObjectAdapter


An ObjectAdapter implemented with a Cursor.

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 methods

void

Changes the underlying cursor to a new cursor.

void

Closes this adapter, closing the backing Cursor as well.

Object
get(int index)

Returns the item for the given position.

final Cursor

Returns the Cursor backing the adapter.

final CursorMapper

Returns the CursorMapper used to convert Cursor rows into Objects.

boolean

Returns true if the adapter, and hence the backing Cursor, is closed; false otherwise.

boolean

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

final void

Sets the CursorMapper used to convert Cursor rows into Objects.

int

Returns the number of items in the adapter.

Cursor

Swap in a new Cursor, returning the old Cursor.

Protected methods

final void
invalidateCache(int index)

Removes an item from the cache.

final void
invalidateCache(int index, int count)

Removes count items starting at index.

void

Called whenever the cursor changes.

void

Called when setMapper is called and a different mapper is provided.

Inherited Constants

From androidx.leanback.widget.ObjectAdapter
static final int
NO_ID = -1

Indicates that an id has not been set.

Inherited methods

From androidx.leanback.widget.ObjectAdapter
long
getId(int position)

Returns the id for the given position.

final Presenter

Returns the Presenter for the given item from the adapter.

final PresenterSelector

Returns the presenter selector for this ObjectAdapter.

final boolean

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

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
notifyItemRangeChanged(int positionStart, int itemCount)

Notifies UI that some items has changed.

final void
notifyItemRangeChanged(int positionStart, int itemCount, Object payload)

Notifies UI that some items has changed.

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 setHasStableIds is called and the status of stable ids has changed.

void

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

final void

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

Sets the presenter selector.

final void

Unregisters all DataObservers for this ObjectAdapter.

final void

Unregisters a DataObserver for data change notifications.

Public constructors

CursorObjectAdapter

public CursorObjectAdapter()

Constructs an adapter.

CursorObjectAdapter

public CursorObjectAdapter(Presenter presenter)

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

CursorObjectAdapter

public CursorObjectAdapter(PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

Public methods

changeCursor

public void changeCursor(Cursor cursor)

Changes the underlying cursor to a new cursor. If there is an existing cursor it will be closed if it is different than the new cursor.

Parameters
Cursor cursor

The new cursor to be used.

close

public void close()

Closes this adapter, closing the backing Cursor as well.

get

public Object get(int index)

Returns the item for the given position.

getCursor

public final Cursor getCursor()

Returns the Cursor backing the adapter.

getMapper

public final CursorMapper getMapper()

Returns the CursorMapper used to convert Cursor rows into Objects.

isClosed

public boolean isClosed()

Returns true if the adapter, and hence the backing Cursor, is closed; false otherwise.

isImmediateNotifySupported

public boolean isImmediateNotifySupported()

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

setMapper

public final void setMapper(CursorMapper mapper)

Sets the CursorMapper used to convert Cursor rows into Objects.

size

public int size()

Returns the number of items in the adapter.

swapCursor

public Cursor swapCursor(Cursor cursor)

Swap in a new Cursor, returning the old Cursor. Unlike changeCursor(Cursor), the returned old Cursor is not closed.

Parameters
Cursor cursor

The new cursor to be used.

Protected methods

invalidateCache

protected final void invalidateCache(int index)

Removes an item from the cache. This will force the item to be re-read from the data source the next time get is called.

invalidateCache

protected final void invalidateCache(int index, int count)

Removes count items starting at index.

onCursorChanged

protected void onCursorChanged()

Called whenever the cursor changes.

onMapperChanged

protected void onMapperChanged()

Called when setMapper is called and a different mapper is provided.