FileDocCategorySizeDatePackage
ArrayObjectAdapter.javaAPI DocAndroid 5.1 API5454Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.widget

ArrayObjectAdapter

public class ArrayObjectAdapter extends ObjectAdapter
An ObjectAdapter implemented with an {@link ArrayList}.

Fields Summary
private ArrayList
mItems
Constructors Summary
public ArrayObjectAdapter(PresenterSelector presenterSelector)
Construct an adapter with the given {@link PresenterSelector}.


                 
       
        super(presenterSelector);
    
public ArrayObjectAdapter(Presenter presenter)
Construct an adapter that uses the given {@link Presenter} for all items.

        super(presenter);
    
public ArrayObjectAdapter()
Construct an adapter.

        super();
    
Methods Summary
public voidadd(java.lang.Object item)
Adds an item to the end of the adapter.

param
item The item to add to the end of the adapter.

        add(mItems.size(), item);
    
public voidadd(int index, java.lang.Object item)
Inserts an item into this adapter at the specified index. If the index is >= {@link #size} an exception will be thrown.

param
index The index at which the item should be inserted.
param
item The item to insert into the adapter.

        mItems.add(index, item);
        notifyItemRangeInserted(index, 1);
    
public voidaddAll(int index, java.util.Collection items)
Adds the objects in the given collection to the adapter, starting at the given index. If the index is >= {@link #size} an exception will be thrown.

param
index The index at which the items should be inserted.
param
items A {@link Collection} of items to insert.

        int itemsCount = items.size();
        if (itemsCount == 0) {
            return;
        }
        mItems.addAll(index, items);
        notifyItemRangeInserted(index, itemsCount);
    
public voidclear()
Removes all items from this adapter, leaving it empty.

        int itemCount = mItems.size();
        if (itemCount == 0) {
            return;
        }
        mItems.clear();
        notifyItemRangeRemoved(0, itemCount);
    
public java.lang.Objectget(int index)

        return mItems.get(index);
    
public intindexOf(java.lang.Object item)
Returns the index for the first occurrence of item in the adapter, or -1 if not found.

param
item The item to find in the list.
return
Index of the first occurrence of the item in the adapter, or -1 if not found.

        return mItems.indexOf(item);
    
public voidnotifyArrayItemRangeChanged(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.

param
positionStart The position of first item that has changed.
param
itemCount The count of how many items have changed.

        notifyItemRangeChanged(positionStart, itemCount);
    
public booleanremove(java.lang.Object item)
Removes the first occurrence of the given item from the adapter.

param
item The item to remove from the adapter.
return
True if the item was found and thus removed from the adapter.

        int index = mItems.indexOf(item);
        if (index >= 0) {
            mItems.remove(index);
            notifyItemRangeRemoved(index, 1);
        }
        return index >= 0;
    
public intremoveItems(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.

param
position The index of the first item to remove.
param
count The number of items to remove.
return
The number of items removed.

        int itemsToRemove = Math.min(count, mItems.size() - position);
        if (itemsToRemove <= 0) {
            return 0;
        }

        for (int i = 0; i < itemsToRemove; i++) {
            mItems.remove(position);
        }
        notifyItemRangeRemoved(position, itemsToRemove);
        return itemsToRemove;
    
public voidreplace(int position, java.lang.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.

param
position The index of item to replace.
param
item The new item to be placed at given position.

        mItems.set(position, item);
        notifyItemRangeChanged(position, 1);
    
public intsize()

        return mItems.size();