belongs to Maven artifact com.android.support:leanback-v17:28.0.0-alpha1
Presenter
public
abstract
class
Presenter
extends Object
implements
FacetProvider
java.lang.Object | |
↳ | android.support.v17.leanback.widget.Presenter |
![]() |
![]() |
A Presenter is used to generate View
s and bind Objects to them on
demand. It is closely related to the concept of an RecyclerView.Adapter
, but is
not position-based. The leanback framework implements the adapter concept using
ObjectAdapter
which refers to a Presenter (or PresenterSelector
) instance.
Presenters should be stateless. Presenters typically extend Presenter.ViewHolder
to store all
necessary view state information, such as references to child views to be used when
binding to avoid expensive calls to findViewById(int)
.
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. } }In addition to view creation and binding, Presenter allows dynamic interface (facet) to be added:
setFacet(Class, Object)
. Supported facets:
ItemAlignmentFacet
is used by