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

ObjectAdapter

public abstract class ObjectAdapter extends Object
Adapter for leanback activities. Provides access to a data model and is decoupled from the presentation of the items via {@link PresenterSelector}.

Fields Summary
public static final int
NO_ID
Indicates that an id has not been set.
private final DataObservable
mObservable
private boolean
mHasStableIds
private PresenterSelector
mPresenterSelector
Constructors Summary
public ObjectAdapter(PresenterSelector presenterSelector)
Construct an adapter with the given {@link PresenterSelector}.


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

        setPresenterSelector(new SinglePresenterSelector(presenter));
    
public ObjectAdapter()
Construct an adapter.

    
Methods Summary
public abstract java.lang.Objectget(int position)
Returns the item for the given position.

public longgetId(int position)
Returns id for the given position.

        return NO_ID;
    
public final PresentergetPresenter(java.lang.Object item)
Returns the {@link Presenter} for the given item from the adapter.

        if (mPresenterSelector == null) {
            throw new IllegalStateException("Presenter selector must not be null");
        }
        return mPresenterSelector.getPresenter(item);
    
public final PresenterSelectorgetPresenterSelector()
Returns the presenter selector for this ObjectAdapter.

        return mPresenterSelector;
    
public final booleanhasStableIds()
Indicates whether the item ids are stable across changes to the underlying data. When this is true, clients of the ObjectAdapter can use {@link #getId(int)} to correlate Objects across changes.

        return mHasStableIds;
    
protected final voidnotifyChanged()

        mObservable.notifyChanged();
    
protected final voidnotifyItemRangeChanged(int positionStart, int itemCount)

        mObservable.notifyItemRangeChanged(positionStart, itemCount);
    
protected final voidnotifyItemRangeInserted(int positionStart, int itemCount)

        mObservable.notifyItemRangeInserted(positionStart, itemCount);
    
protected final voidnotifyItemRangeRemoved(int positionStart, int itemCount)

        mObservable.notifyItemRangeRemoved(positionStart, itemCount);
    
protected voidonHasStableIdsChanged()
Called when {@link #setHasStableIds(boolean)} is called and the status of stable ids has changed.

    
protected voidonPresenterSelectorChanged()
Called when {@link #setPresenterSelector(PresenterSelector)} is called and the PresenterSelector differs from the previous one.

    
public final voidregisterObserver(android.support.v17.leanback.widget.ObjectAdapter$DataObserver observer)
Register a DataObserver for data change notifications.

        mObservable.registerObserver(observer);
    
public final voidsetHasStableIds(boolean hasStableIds)
Sets whether the item ids are stable across changes to the underlying data.

        boolean changed = mHasStableIds != hasStableIds;
        mHasStableIds = hasStableIds;

        if (changed) {
            onHasStableIdsChanged();
        }
    
public final voidsetPresenterSelector(PresenterSelector presenterSelector)
Set the presenter selector. May not be null.

        if (presenterSelector == null) {
            throw new IllegalArgumentException("Presenter selector must not be null");
        }
        final boolean update = (mPresenterSelector != null);
        final boolean selectorChanged = update && mPresenterSelector != presenterSelector;

        mPresenterSelector = presenterSelector;

        if (selectorChanged) {
            onPresenterSelectorChanged();
        }
        if (update) {
            notifyChanged();
        }
    
public abstract intsize()
Returns the number of items in the adapter.

public final voidunregisterAllObservers()
Unregister all DataObservers for this ObjectAdapter.

        mObservable.unregisterAll();
    
public final voidunregisterObserver(android.support.v17.leanback.widget.ObjectAdapter$DataObserver observer)
Unregister a DataObserver for data change notifications.

        mObservable.unregisterObserver(observer);