Android APIs
public abstract class

Presenter

extends Object
java.lang.Object
   ↳ android.support.v17.leanback.widget.Presenter
Known Direct Subclasses
Known Indirect Subclasses

Class Overview

A Presenter is used to generate Views and bind Objects to them on demand. It is closely related to concept of an RecyclerView.Adapter, but is not position-based.

A trivial Presenter that takes a string and renders it into a TextView:

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

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

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

         textView.setText(item);
     }

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

Summary

Nested Classes
class Presenter.ViewHolder ViewHolder can be subclassed and used to cache any view accessors needed to improve binding performance (for example, results of findViewById) without needing to subclass a View. 
Public Constructors
Presenter()
Public Methods
abstract void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item)
Binds a View to an item.
abstract Presenter.ViewHolder onCreateViewHolder(ViewGroup parent)
Creates a new View.
abstract void onUnbindViewHolder(Presenter.ViewHolder viewHolder)
Unbinds a View from an item.
void onViewAttachedToWindow(Presenter.ViewHolder holder)
Called when a view created by this presenter has been attached to a window.
void onViewDetachedFromWindow(Presenter.ViewHolder holder)
Called when a view created by this presenter has been detached from its window.
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public Presenter ()

Public Methods

public abstract void onBindViewHolder (Presenter.ViewHolder viewHolder, Object item)

Binds a View to an item.

public abstract Presenter.ViewHolder onCreateViewHolder (ViewGroup parent)

Creates a new View.

public abstract void onUnbindViewHolder (Presenter.ViewHolder viewHolder)

Unbinds a 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 void onViewAttachedToWindow (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 onViewDetachedFromWindow(ViewHolder) those resources should be restored here.

Parameters
holder Holder of the view being attached

public void onViewDetachedFromWindow (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 an detaching them as appropriate.

Parameters
holder Holder of the view being detached