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.

@Nullable 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 @Nullable Presenter

Returns the Presenter for the given item from the adapter.

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.

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,
    @Nullable 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

Added in 1.1.0
public CursorObjectAdapter()

Constructs an adapter.

CursorObjectAdapter

Added in 1.1.0
public CursorObjectAdapter(Presenter presenter)

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

CursorObjectAdapter

Added in 1.1.0
public CursorObjectAdapter(PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

Public methods

changeCursor

Added in 1.1.0
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

Added in 1.1.0
public void close()

Closes this adapter, closing the backing Cursor as well.

get

Added in 1.2.0-alpha04
public @Nullable Object get(int index)

Returns the item for the given position.

getCursor

Added in 1.1.0
public final Cursor getCursor()

Returns the Cursor backing the adapter.

getMapper

Added in 1.1.0
public final CursorMapper getMapper()

Returns the CursorMapper used to convert Cursor rows into Objects.

isClosed

Added in 1.1.0
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

Added in 1.1.0
public final void setMapper(CursorMapper mapper)

Sets the CursorMapper used to convert Cursor rows into Objects.

size

Added in 1.2.0-alpha04
public int size()

Returns the number of items in the adapter.

swapCursor

Added in 1.1.0
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

Added in 1.1.0
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

Added in 1.1.0
protected final void invalidateCache(int index, int count)

Removes count items starting at index.

onCursorChanged

Added in 1.1.0
protected void onCursorChanged()

Called whenever the cursor changes.

onMapperChanged

Added in 1.1.0
protected void onMapperChanged()

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