-
- All Implemented Interfaces:
public abstract class PresenterA Presenter is used to generate Views and bind Objects to them on demand. It is closely related to the concept of an [ ], but is not position-based. The leanback framework implements the adapter concept using AnyAdapter which refers to a Presenter (or PresenterSelector) instance.
Presenters should be stateless. Presenters typically extend androidx.recyclerview.widget.RecyclerView.ViewHolder to store all necessary view state information, such as references to child views to be used when binding to avoid expensive calls to View.findViewById.
A trivial Presenter that takes a string and renders it into a [ ]:
<pre class="prettyprint"> public class StringTextViewPresenter extends Presenter { // This class does not need a custom ViewHolder, since it does not use // a complex layout.
-
-
Constructor Summary
Constructors Constructor Description Presenter()
-
Method Summary
Modifier and Type Method Description abstract IntegergetLayoutId()final RecyclerView.ViewHolderonCreateViewHolder(ViewGroup parent)Creates a new View. abstract RecyclerView.ViewHolderonCreateViewHolder(View itemView, ViewGroup parent)abstract UnitonBindViewHolder(RecyclerView.ViewHolder viewHolder, Object item)Binds a View to an item. UnitonUnbindViewHolder(RecyclerView.ViewHolder viewHolder)Unbinds a View from an item. final UnitonViewAttachedToWindow(RecyclerView.ViewHolder holder)Called when a view created by this presenter has been attached to a window. final UnitonViewDetachedFromWindow(RecyclerView.ViewHolder holder)Called when a view created by this presenter has been detached from its window. final UnitsetOnClickListener(RecyclerView.ViewHolder holder, View.OnClickListener listener)Called to set a click listener for the given view holder. -
-
Method Detail
-
getLayoutId
@LayoutRes() abstract Integer getLayoutId()
-
onCreateViewHolder
final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent)
Creates a new View.
-
onCreateViewHolder
abstract RecyclerView.ViewHolder onCreateViewHolder(View itemView, ViewGroup parent)
-
onBindViewHolder
abstract Unit onBindViewHolder(RecyclerView.ViewHolder viewHolder, Object item)
Binds a View to an item.
-
onUnbindViewHolder
Unit onUnbindViewHolder(RecyclerView.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.
-
onViewAttachedToWindow
final Unit onViewAttachedToWindow(RecyclerView.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 those resources should be restored here.
- Parameters:
holder- Holder of the view being attached
-
onViewDetachedFromWindow
final Unit onViewDetachedFromWindow(RecyclerView.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.
- Parameters:
holder- Holder of the view being detached
-
setOnClickListener
final Unit setOnClickListener(RecyclerView.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).
- Parameters:
holder- The view holder containing the view(s) on which the listener should be set.listener- The click listener to be set.
-
-
-
-