Join us on the livestream at Android Dev Summit on 7-8 November 2018, starting at 10AM PDT!
added in version 1.0.0
belongs to Maven artifact androidx.leanback:leanback:1.0.0

CursorObjectAdapter

public class CursorObjectAdapter
extends ObjectAdapter

java.lang.Object
   ↳ androidx.leanback.widget.ObjectAdapter
     ↳ androidx.leanback.widget.CursorObjectAdapter


An ObjectAdapter implemented with a Cursor.

Summary

Inherited constants

Public constructors

CursorObjectAdapter(PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

CursorObjectAdapter(Presenter presenter)

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

CursorObjectAdapter()

Constructs an adapter.

Public methods

void changeCursor(Cursor cursor)

Changes the underlying cursor to a new cursor.

void close()

Closes this adapter, closing the backing Cursor as well.

Object get(int index)

Returns the item for the given position.

final Cursor getCursor()

Returns the Cursor backing the adapter.

final CursorMapper getMapper()

Returns the CursorMapper used to convert Cursor rows into Objects.

boolean isClosed()

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

boolean isImmediateNotifySupported()

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

final void setMapper(CursorMapper mapper)

Sets the CursorMapper used to convert Cursor rows into Objects.

int size()

Returns the number of items in the adapter.

Cursor swapCursor(Cursor 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 onCursorChanged()

Called whenever the cursor changes.

void onMapperChanged()

Called when setMapper(CursorMapper) is called and a different mapper is provided.

Inherited methods

Public constructors

CursorObjectAdapter

added in version 1.0.0
public CursorObjectAdapter (PresenterSelector presenterSelector)

Constructs an adapter with the given PresenterSelector.

Parameters
presenterSelector PresenterSelector

CursorObjectAdapter

added in version 1.0.0
public CursorObjectAdapter (Presenter presenter)

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

Parameters
presenter Presenter

CursorObjectAdapter

added in version 1.0.0
public CursorObjectAdapter ()

Constructs an adapter.

Public methods

changeCursor

added in version 1.0.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 version 1.0.0
public void close ()

Closes this adapter, closing the backing Cursor as well.

get

added in version 1.0.0
public Object get (int index)

Returns the item for the given position.

Parameters
index int

Returns
Object

getCursor

added in version 1.0.0
public final Cursor getCursor ()

Returns the Cursor backing the adapter.

Returns
Cursor

getMapper

added in version 1.0.0
public final CursorMapper getMapper ()

Returns the CursorMapper used to convert Cursor rows into Objects.

Returns
CursorMapper

isClosed

added in version 1.0.0
public boolean isClosed ()

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

Returns
boolean

isImmediateNotifySupported

added in version 1.0.0
public boolean isImmediateNotifySupported ()

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

Returns
boolean

setMapper

added in version 1.0.0
public final void setMapper (CursorMapper mapper)

Sets the CursorMapper used to convert Cursor rows into Objects.

Parameters
mapper CursorMapper

size

added in version 1.0.0
public int size ()

Returns the number of items in the adapter.

Returns
int

swapCursor

added in version 1.0.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.

Returns
Cursor

Protected methods

invalidateCache

added in version 1.0.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(int) is called.

Parameters
index int

invalidateCache

added in version 1.0.0
protected final void invalidateCache (int index, 
                int count)

Removes count items starting at index.

Parameters
index int

count int

onCursorChanged

added in version 1.0.0
protected void onCursorChanged ()

Called whenever the cursor changes.

onMapperChanged

added in version 1.0.0
protected void onMapperChanged ()

Called when setMapper(CursorMapper) is called and a different mapper is provided.