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

Presenter

public abstract class Presenter extends Object
A Presenter is used to generate {@link View}s and bind Objects to them on demand. It is closely related to concept of an {@link android.support.v7.widget.RecyclerView.Adapter RecyclerView.Adapter}, but is not position-based.

A trivial Presenter that takes a string and renders it into a {@link android.widget.TextView TextView}:

public class StringTextViewPresenter extends Presenter {
// This class does not need a custom ViewHolder, since it does not use
// a complex layout.

{@literal @}Override
public ViewHolder onCreateViewHolder(ViewGroup parent) {
return new ViewHolder(new TextView(parent.getContext()));
}

{@literal @}Override
public void onBindViewHolder(ViewHolder viewHolder, Object item) {
String str = (String) item;
TextView textView = (TextView) viewHolder.mView;

textView.setText(item);
}

{@literal @}Override
public void onUnbindViewHolder(ViewHolder viewHolder) {
// Nothing to unbind for TextView, but if this viewHolder had
// allocated bitmaps, they can be released here.
}
}

Fields Summary
Constructors Summary
Methods Summary
protected static voidcancelAnimationsRecursive(android.view.View view)
Utility method for removing all running animations on a view.

        if (view != null && view.hasTransientState()) {
            view.animate().cancel();
            if (view instanceof ViewGroup) {
                final int count = ((ViewGroup) view).getChildCount();
                for (int i = 0; view.hasTransientState() && i < count; i++) {
                    cancelAnimationsRecursive(((ViewGroup) view).getChildAt(i));
                }
            }
        }
    
public abstract voidonBindViewHolder(android.support.v17.leanback.widget.Presenter$ViewHolder viewHolder, java.lang.Object item)
Binds a {@link View} to an item.

public abstract android.support.v17.leanback.widget.Presenter$ViewHolderonCreateViewHolder(android.view.ViewGroup parent)
Creates a new {@link View}.

public abstract voidonUnbindViewHolder(android.support.v17.leanback.widget.Presenter$ViewHolder viewHolder)
Unbinds a {@link View} from an item. Any expensive references may be released here, and any fields that are not bound for every item should be cleared here.

public voidonViewAttachedToWindow(android.support.v17.leanback.widget.Presenter$ViewHolder holder)
Called when a view created by this presenter has been attached to a window.

This can be used as a reasonable signal that the view is about to be seen by the user. If the adapter previously freed any resources in {@link #onViewDetachedFromWindow(ViewHolder)} those resources should be restored here.

param
holder Holder of the view being attached

    
public voidonViewDetachedFromWindow(android.support.v17.leanback.widget.Presenter$ViewHolder holder)
Called when a view created by this presenter has been detached from its window.

Becoming detached from the window is not necessarily a permanent condition; the consumer of an presenter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.

Any view property animations should be cancelled here or the view may fail to be recycled.

param
holder Holder of the view being detached

        // If there are view property animations running then RecyclerView won't recycle.
        cancelAnimationsRecursive(holder.view);
    
public voidsetOnClickListener(android.support.v17.leanback.widget.Presenter$ViewHolder holder, View.OnClickListener listener)
Called to set a click listener for the given view holder. The default implementation sets the click listener on the root view in the view holder. If the root view isn't focusable this method should be overridden to set the listener on the appropriate focusable child view(s).

param
holder The view holder containing the view(s) on which the listener should be set.
param
listener The click listener to be set.

        holder.view.setOnClickListener(listener);