ArrayObjectAdapter
public class ArrayObjectAdapter extends ObjectAdapter
| java.lang.Object | ||
| ↳ | androidx.leanback.widget.ObjectAdapter | |
| ↳ | androidx.leanback.widget.ArrayObjectAdapter |
An ObjectAdapter implemented with an ArrayList.
Summary
Public constructors |
|---|
|
Constructs an adapter. |
ArrayObjectAdapter(@NonNull Presenter presenter)Constructs an adapter that uses the given |
ArrayObjectAdapter(@NonNull PresenterSelector presenterSelector)Constructs an adapter with the given |
Public methods |
|
|---|---|
void |
Adds an item to the end of the adapter. |
void |
Inserts an item into this adapter at the specified index. |
void |
addAll(int index, @NonNull Collection<Object> items)Adds the objects in the given collection to the adapter, starting at the given index. |
void |
clear()Removes all items from this adapter, leaving it empty. |
@Nullable Object |
get(int index)Returns the item for the given position. |
int |
Returns the index for the first occurrence of item in the adapter, or -1 if not found. |
boolean |
Returns true if the adapter pairs each underlying data change with a call to notify and false otherwise. |
void |
move(int fromPosition, int toPosition)Moved the item at fromPosition to toPosition. |
void |
notifyArrayItemRangeChanged(int positionStart, int itemCount)Notify that the content of a range of items changed. |
boolean |
Removes the first occurrence of the given item from the adapter. |
int |
removeItems(int position, int count)Removes a range of items from the adapter. |
void |
Replaces item at position with a new item and calls notifyItemRangeChanged() at the given position. |
void |
setItems(@NonNull List itemList, @Nullable DiffCallback callback)Set a new item list to adapter. |
int |
size()Returns the number of items in the adapter. |
@NonNull List<E> |
<E> unmodifiableList()Gets a read-only view of the list of object of this ArrayObjectAdapter. |
Inherited Constants |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
ArrayObjectAdapter
public ArrayObjectAdapter(@NonNull Presenter presenter)
Constructs an adapter that uses the given Presenter for all items.
ArrayObjectAdapter
public ArrayObjectAdapter(@NonNull PresenterSelector presenterSelector)
Constructs an adapter with the given PresenterSelector.
Public methods
add
public void add(int index, @NonNull Object item)
Inserts an item into this adapter at the specified index. If the index is >size an exception will be thrown.
addAll
public void addAll(int index, @NonNull Collection<Object> items)
Adds the objects in the given collection to the adapter, starting at the given index. If the index is >= size an exception will be thrown.
| Parameters | |
|---|---|
int index |
The index at which the items should be inserted. |
@NonNull Collection<Object> items |
A |
indexOf
public int indexOf(@NonNull Object item)
Returns the index for the first occurrence of item in the adapter, or -1 if not found.
| 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
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
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
public boolean remove(@NonNull Object item)
Removes the first occurrence of the given item from the adapter.
| Returns | |
|---|---|
boolean |
True if the item was found and thus removed from the adapter. |
removeItems
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
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.
setItems
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 | |
|---|---|
@NonNull List itemList |
List of new Items |
@Nullable DiffCallback callback |
Optional DiffCallback Object to compute the difference between the old data set and new data set. When null, |
unmodifiableList
public @NonNull List<E> <E> unmodifiableList()
Gets a read-only view of the list of object of this ArrayObjectAdapter.