# CursorObjectAdapter

Artifact: [androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback) [View Source](https://cs.android.com/search?q=file:androidx/leanback/widget/CursorObjectAdapter.java+class:androidx.leanback.widget.CursorObjectAdapter) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***


```
public class CursorObjectAdapter extends ObjectAdapter
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.leanback.widget.ObjectAdapter](https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter) ||
|   | ↳ | [androidx.leanback.widget.CursorObjectAdapter](https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter) |

*** ** * ** ***

An `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter` implemented with a `https://developer.android.com/reference/android/database/Cursor.html`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#CursorObjectAdapter()()` Constructs an adapter. |
| `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#CursorObjectAdapter(androidx.leanback.widget.Presenter)(https://developer.android.com/reference/androidx/leanback/widget/Presenter presenter)` Constructs an adapter that uses the given `https://developer.android.com/reference/androidx/leanback/widget/Presenter` for all items. |
| `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#CursorObjectAdapter(androidx.leanback.widget.PresenterSelector)(https://developer.android.com/reference/androidx/leanback/widget/PresenterSelector presenterSelector)` Constructs an adapter with the given `https://developer.android.com/reference/androidx/leanback/widget/PresenterSelector`. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#changeCursor(android.database.Cursor)(https://developer.android.com/reference/android/database/Cursor.html cursor)` Changes the underlying cursor to a new cursor. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#close()()` Closes this adapter, closing the backing `https://developer.android.com/reference/android/database/Cursor.html` as well. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#get(int)(int index)` Returns the item for the given position. |
| `final https://developer.android.com/reference/android/database/Cursor.html` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#getCursor()()` Returns the `https://developer.android.com/reference/android/database/Cursor.html` backing the adapter. |
| `final https://developer.android.com/reference/androidx/leanback/database/CursorMapper` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#getMapper()()` Returns the `https://developer.android.com/reference/androidx/leanback/database/CursorMapper` used to convert `https://developer.android.com/reference/android/database/Cursor.html` rows into Objects. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#isClosed()()` Returns true if the adapter, and hence the backing `https://developer.android.com/reference/android/database/Cursor.html`, is closed; false otherwise. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#isImmediateNotifySupported()()` Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#setMapper(androidx.leanback.database.CursorMapper)(https://developer.android.com/reference/androidx/leanback/database/CursorMapper mapper)` Sets the `https://developer.android.com/reference/androidx/leanback/database/CursorMapper` used to convert `https://developer.android.com/reference/android/database/Cursor.html` rows into Objects. |
| `int` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#size()()` Returns the number of items in the adapter. |
| `https://developer.android.com/reference/android/database/Cursor.html` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#swapCursor(android.database.Cursor)(https://developer.android.com/reference/android/database/Cursor.html cursor)` Swap in a new Cursor, returning the old Cursor. |

| ### Protected methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#invalidateCache(int)(int index)` Removes an item from the cache. |
| `final void` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#invalidateCache(int,int)(int index, int count)` Removes `count` items starting at `index`. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#onCursorChanged()()` Called whenever the cursor changes. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#onMapperChanged()()` Called when `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#setMapper(androidx.leanback.database.CursorMapper)` is called and a different mapper is provided. |

| ### Inherited Constants |
|---|
| From [androidx.leanback.widget.ObjectAdapter](https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter) |---|---| | `static final int` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#NO_ID() = -1` Indicates that an id has not been set. | |

| ### Inherited methods |
|---|
| From [androidx.leanback.widget.ObjectAdapter](https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter) |---|---| | `long` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#getId(int)(int position)` Returns the id for the given position. | | `final @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/leanback/widget/Presenter` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#getPresenter(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item)` Returns the `https://developer.android.com/reference/androidx/leanback/widget/Presenter` for the given item from the adapter. | | `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/widget/PresenterSelector` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#getPresenterSelector()()` Returns the presenter selector for this ObjectAdapter. | | `final boolean` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#hasStableIds()()` Returns true if the item ids are stable across changes to the underlying data. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#notifyChanged()()` Notifies UI that the underlying data has changed. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#notifyItemMoved(int,int)(int fromPosition, int toPosition)` Notifies UI that item at fromPosition has been moved to toPosition. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#notifyItemRangeChanged(int,int)(int positionStart, int itemCount)` Notifies UI that some items has changed. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#notifyItemRangeChanged(int,int,java.lang.Object)( int positionStart, int itemCount, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html payload )` Notifies UI that some items has changed. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#notifyItemRangeInserted(int,int)(int positionStart, int itemCount)` Notifies UI that new items has been inserted. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#notifyItemRangeRemoved(int,int)(int positionStart, int itemCount)` Notifies UI that some items that has been removed. | | `void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#onHasStableIdsChanged()()` Called when `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#setHasStableIds(boolean)` is called and the status of stable ids has changed. | | `void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#onPresenterSelectorChanged()()` Called when `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#setPresenterSelector(androidx.leanback.widget.PresenterSelector)` is called and the PresenterSelector differs from the previous one. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#registerObserver(androidx.leanback.widget.ObjectAdapter.DataObserver)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter.DataObserver observer)` Registers a DataObserver for data change notifications. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#setHasStableIds(boolean)(boolean hasStableIds)` Sets whether the item ids are stable across changes to the underlying data. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#setPresenterSelector(androidx.leanback.widget.PresenterSelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/widget/PresenterSelector presenterSelector)` Sets the presenter selector. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#unregisterAllObservers()()` Unregisters all DataObservers for this ObjectAdapter. | | `final void` | `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#unregisterObserver(androidx.leanback.widget.ObjectAdapter.DataObserver)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter.DataObserver observer)` Unregisters a DataObserver for data change notifications. | |

## Public constructors

### CursorObjectAdapter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public CursorObjectAdapter()
```

Constructs an adapter.

### CursorObjectAdapter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public CursorObjectAdapter(Presenter presenter)
```

Constructs an adapter that uses the given `https://developer.android.com/reference/androidx/leanback/widget/Presenter` for all items.

### CursorObjectAdapter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public CursorObjectAdapter(PresenterSelector presenterSelector)
```

Constructs an adapter with the given `https://developer.android.com/reference/androidx/leanback/widget/PresenterSelector`.

## Public methods

### changeCursor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#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 |
|---|---|
| `https://developer.android.com/reference/android/database/Cursor.html cursor` | The new cursor to be used. |

### close

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public void close()
```

Closes this adapter, closing the backing `https://developer.android.com/reference/android/database/Cursor.html` as well.

### get

```
public @Nullable Object get(int index)
```

Returns the item for the given position.

### getCursor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public final Cursor getCursor()
```

Returns the `https://developer.android.com/reference/android/database/Cursor.html` backing the adapter.

### getMapper

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public final CursorMapper getMapper()
```

Returns the `https://developer.android.com/reference/androidx/leanback/database/CursorMapper` used to convert `https://developer.android.com/reference/android/database/Cursor.html` rows into Objects.

### isClosed

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public boolean isClosed()
```

Returns true if the adapter, and hence the backing `https://developer.android.com/reference/android/database/Cursor.html`, 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](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
public final void setMapper(CursorMapper mapper)
```

Sets the `https://developer.android.com/reference/androidx/leanback/database/CursorMapper` used to convert `https://developer.android.com/reference/android/database/Cursor.html` rows into Objects.

### size

```
public int size()
```

Returns the number of items in the adapter.

### swapCursor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#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 |
|---|---|
| `https://developer.android.com/reference/android/database/Cursor.html cursor` | The new cursor to be used. |

## Protected methods

### invalidateCache

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#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 `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#get(int)` is called.

### invalidateCache

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected final void invalidateCache(int index, int count)
```

Removes `count` items starting at `index`.

### onCursorChanged

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected void onCursorChanged()
```

Called whenever the cursor changes.

### onMapperChanged

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

```
protected void onMapperChanged()
```

Called when `https://developer.android.com/reference/androidx/leanback/widget/CursorObjectAdapter#setMapper(androidx.leanback.database.CursorMapper)` is called and a different mapper is provided.