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

SparseArrayObjectAdapter

public class SparseArrayObjectAdapter extends ObjectAdapter
An ObjectAdapter implemented with a {@link android.util.SparseArray}. This class maintains an array of objects where each object is associated with an integer key which determines its order relative to other objects.

Fields Summary
private android.util.SparseArray
mItems
Constructors Summary
public SparseArrayObjectAdapter(PresenterSelector presenterSelector)
Construct an adapter with the given {@link PresenterSelector}.


                 
       
        super(presenterSelector);
    
public SparseArrayObjectAdapter(Presenter presenter)
Construct an adapter with the given {@link Presenter}.

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

        super();
    
Methods Summary
public voidclear(int key)
Clears the given key and associated item from the adapter.

param
key The key to be cleared.

        int index = mItems.indexOfKey(key);
        if (index >= 0) {
            mItems.removeAt(index);
            notifyItemRangeRemoved(index, 1);
        }
    
public voidclear()
Removes all items from this adapter, leaving it empty.

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

        return mItems.valueAt(position);
    
public intindexOf(java.lang.Object item)
Returns the index for the given item in the adapter.

param
item The item to find in the array.
return
Index of the item, or a negative value if not found.

        return mItems.indexOfValue(item);
    
public intindexOf(int key)
Returns the index for the given key in the adapter.

param
key The key to find in the array.
return
Index of the item, or a negative value if not found.

        return mItems.indexOfKey(key);
    
public java.lang.Objectlookup(int key)
Returns the object for the given key, or null if no mapping for that key exists.

        return mItems.get(key);
    
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 voidset(int key, java.lang.Object item)
Sets the item for the given key.

param
key The key associated with the item.
param
item The item associated with the key.

        int index = mItems.indexOfKey(key);
        if (index >= 0) {
            if (mItems.valueAt(index) != item) {
                mItems.setValueAt(index, item);
                notifyItemRangeChanged(index, 1);
            }
        } else {
            mItems.append(key, item);
            index = mItems.indexOfKey(key);
            notifyItemRangeInserted(index, 1);
        }
    
public intsize()

        return mItems.size();