# ArrayObjectAdapter

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

*** ** * ** ***

<br />

```
public class ArrayObjectAdapter 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.ArrayObjectAdapter](https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter) |

*** ** * ** ***

An `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter` implemented with an `https://developer.android.com/reference/java/util/ArrayList.html`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#ArrayObjectAdapter()()` Constructs an adapter. |
| `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#ArrayObjectAdapter(androidx.leanback.widget.Presenter)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html 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/ArrayObjectAdapter#ArrayObjectAdapter(androidx.leanback.widget.PresenterSelector)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html 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/ArrayObjectAdapter#add(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item)` Adds an item to the end of the adapter. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#add(int,java.lang.Object)(int index, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item)` Inserts an item into this adapter at the specified index. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#addAll(int,java.util.Collection<?>)(int index, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> items)` Adds the objects in the given collection to the adapter, starting at the given index. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#clear()()` Removes all items from this adapter, leaving it empty. |
| `@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/ArrayObjectAdapter#get(int)(int index)` Returns the item for the given position. |
| `int` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#indexOf(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 index for the first occurrence of item in the adapter, or -1 if not found. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#isImmediateNotifySupported()()` Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#move(int,int)(int fromPosition, int toPosition)` Moved the item at fromPosition to toPosition. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#notifyArrayItemRangeChanged(int,int)(int positionStart, int itemCount)` Notify that the content of a range of items changed. |
| `boolean` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#remove(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item)` Removes the first occurrence of the given item from the adapter. |
| `int` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#removeItems(int,int)(int position, int count)` Removes a range of items from the adapter. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#replace(int,java.lang.Object)(int position, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item)` Replaces item at position with a new item and calls notifyItemRangeChanged() at the given position. |
| `void` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#setItems(java.util.List,androidx.leanback.widget.DiffCallback)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html itemList, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/leanback/widget/DiffCallback callback)` Set a new item list to adapter. |
| `int` | `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#size()()` Returns the number of items in the adapter. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html<E>` | `<E> https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#unmodifiableList()()` Gets a read-only view of the list of object of this ArrayObjectAdapter. |

### 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

### ArrayObjectAdapter

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

```
public ArrayObjectAdapter()
```

Constructs an adapter.

### ArrayObjectAdapter

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

```
public ArrayObjectAdapter(@NonNull Presenter presenter)
```

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

### ArrayObjectAdapter

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

```
public ArrayObjectAdapter(@NonNull PresenterSelector presenterSelector)
```

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

## Public methods

### add

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

```
public void add(@NonNull Object item)
```

Adds an item to the end of the adapter.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item` | The item to add to the end of the adapter. |

### add

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

```
public void add(int index, @NonNull Object item)
```

Inserts an item into this adapter at the specified index. If the index is \>`https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#size()` an exception will be thrown.

| Parameters |
|---|---|
| `int index` | The index at which the item should be inserted. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item` | The item to insert into the adapter. |

### addAll

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

```
public void addAll(int index, @NonNull Collection<@NonNull ?> items)
```

Adds the objects in the given collection to the adapter, starting at the given index. If the index is \>= `https://developer.android.com/reference/androidx/leanback/widget/ArrayObjectAdapter#size()` an exception will be thrown.

| Parameters |
|---|---|
| `int index` | The index at which the items should be inserted. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/Collection.html<@https://developer.android.com/reference/androidx/annotation/NonNull ?> items` | A `https://developer.android.com/reference/java/util/Collection.html` of items to insert. |

### clear

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

```
public void clear()
```

Removes all items from this adapter, leaving it empty.

### get

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

Returns the item for the given position.

### indexOf

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

```
public int indexOf(@NonNull Object item)
```

Returns the index for the first occurrence of item in the adapter, or -1 if not found.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item` | The item to find in the list. |

| Returns |
|---|---|
| `int` | Index of the first occurrence of the item in the adapter, or -1 if not found. |

### isImmediateNotifySupported

```
public boolean isImmediateNotifySupported()
```

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

### move

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

```
public void move(int fromPosition, int toPosition)
```

Moved the item at fromPosition to toPosition.

| Parameters |
|---|---|
| `int fromPosition` | Previous position of the item. |
| `int toPosition` | New position of the item. |

### notifyArrayItemRangeChanged

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

```
public void notifyArrayItemRangeChanged(int positionStart, int itemCount)
```

Notify that the content of a range of items changed. Note that this is not same as items being added or removed.

| Parameters |
|---|---|
| `int positionStart` | The position of first item that has changed. |
| `int itemCount` | The count of how many items have changed. |

### remove

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

```
public boolean remove(@NonNull Object item)
```

Removes the first occurrence of the given item from the adapter.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item` | The item to remove from the adapter. |

| Returns |
|---|---|
| `boolean` | True if the item was found and thus removed from the adapter. |

### removeItems

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

```
public int removeItems(int position, int count)
```

Removes a range of items from the adapter. The range is specified by giving the starting position and the number of elements to remove.

| Parameters |
|---|---|
| `int position` | The index of the first item to remove. |
| `int count` | The number of items to remove. |

| Returns |
|---|---|
| `int` | The number of items removed. |

### replace

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

```
public void replace(int position, @NonNull Object item)
```

Replaces item at position with a new item and calls notifyItemRangeChanged() at the given position. Note that this method does not compare new item to existing item.

| Parameters |
|---|---|
| `int position` | The index of item to replace. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/Object.html item` | The new item to be placed at given position. |

### setItems

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

```
public void setItems(@NonNull List itemList, @Nullable DiffCallback callback)
```

Set a new item list to adapter. The DiffUtil will compute the difference and dispatch it to specified position.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/util/List.html itemList` | List of new Items |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/androidx/leanback/widget/DiffCallback callback` | Optional DiffCallback Object to compute the difference between the old data set and new data set. When null, `https://developer.android.com/reference/androidx/leanback/widget/ObjectAdapter#notifyChanged()` will be fired. |

### size

```
public int size()
```

Returns the number of items in the adapter.

### unmodifiableList

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

```
public @NonNull List<E> <E> unmodifiableList()
```

Gets a read-only view of the list of object of this ArrayObjectAdapter.