ItemBridgeAdapter
public class ItemBridgeAdapter extends RecyclerView.Adapter implements FacetProviderAdapter
| java.lang.Object | ||
| ↳ | androidx.recyclerview.widget.RecyclerView.Adapter | |
| ↳ | androidx.leanback.widget.ItemBridgeAdapter |
Bridge from Presenter to RecyclerView.Adapter. Public to allow use by third party Presenters.
Summary
Nested types |
|---|
public class ItemBridgeAdapter.AdapterListenerInterface for listening to ViewHolder operations. |
public class ItemBridgeAdapter.ViewHolder extends RecyclerView.ViewHolder implements FacetProviderViewHolder for the ItemBridgeAdapter. |
public abstract class ItemBridgeAdapter.WrapperInterface for wrapping a view created by a Presenter into another view. |
Public constructors |
|---|
ItemBridgeAdapter(ObjectAdapter adapter) |
ItemBridgeAdapter( |
Public methods |
|
|---|---|
void |
clear()Clears the adapter. |
FacetProvider |
getFacetProvider(int type)Queries |
int |
Returns the total number of items in the data set held by the adapter. |
long |
getItemId(int position)Return the stable ID for the item at |
int |
getItemViewType(int position)Return the view type of the item at |
ArrayList<Presenter> |
Returns the presenter mapper array. |
ItemBridgeAdapter.Wrapper |
Returns the |
final void |
onBindViewHolder(RecyclerView.ViewHolder holder, int position)Called by RecyclerView to display the data at the specified position. |
final void |
onBindViewHolder(Called by RecyclerView to display the data at the specified position. |
final RecyclerView.ViewHolder |
onCreateViewHolder(ViewGroup parent, int viewType)
|
final boolean |
Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state. |
final void |
Called when a view created by this adapter has been attached to a window. |
final void |
Called when a view created by this adapter has been detached from its window. |
final void |
Called when a view created by this adapter has been recycled. |
void |
setAdapter(ObjectAdapter adapter)Sets the |
void |
Sets the AdapterListener. |
void |
setPresenter(PresenterSelector presenterSelector)Changes Presenter that creates and binds the view. |
void |
setPresenterMapper(ArrayList<Presenter> presenters)Sets the presenter mapper array. |
void |
setWrapper(ItemBridgeAdapter.Wrapper wrapper)Sets the |
Protected methods |
|
|---|---|
void |
onAddPresenter(Presenter presenter, int type)Called when presenter is added to Adapter. |
void |
onAttachedToWindow(ItemBridgeAdapter.ViewHolder viewHolder)Called when ViewHolder has been attached to window. |
void |
onBind(ItemBridgeAdapter.ViewHolder viewHolder)Called when ViewHolder has been bound to data. |
void |
onCreate(ItemBridgeAdapter.ViewHolder viewHolder)Called when ViewHolder is created. |
void |
onDetachedFromWindow(ItemBridgeAdapter.ViewHolder viewHolder)Called when ViewHolder has been detached from window. |
void |
onUnbind(ItemBridgeAdapter.ViewHolder viewHolder)Called when ViewHolder has been unbound from data. |
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
ItemBridgeAdapter
public ItemBridgeAdapter(
ObjectAdapter adapter,
PresenterSelector presenterSelector
)
Public methods
getFacetProvider
public FacetProvider getFacetProvider(int type)
Queries FacetProvider for a given type within Adapter.
| Parameters | |
|---|---|
int type |
type of the item. |
| Returns | |
|---|---|
FacetProvider |
Facet provider for the type. |
getItemCount
public int getItemCount()
Returns the total number of items in the data set held by the adapter.
| Returns | |
|---|---|
int |
The total number of items in this adapter. |
getItemId
public long getItemId(int position)
Return the stable ID for the item at position. If hasStableIds would return false this method should return NO_ID. The default implementation of this method returns NO_ID.
| Parameters | |
|---|---|
int position |
Adapter position to query |
| Returns | |
|---|---|
long |
the stable ID of the item at position |
getItemViewType
public int getItemViewType(int position)
Return the view type of the item at position for the purposes of view recycling.
The default implementation of this method returns 0, making the assumption of a single view type for the adapter. Unlike ListView adapters, types need not be contiguous. Consider using id resources to uniquely identify item view types.
| Parameters | |
|---|---|
int position |
position to query |
| Returns | |
|---|---|
int |
integer value identifying the type of the view needed to represent the item at |
getPresenterMapper
public ArrayList<Presenter> getPresenterMapper()
Returns the presenter mapper array.
onBindViewHolder
public final void onBindViewHolder(RecyclerView.ViewHolder holder, int position)
Called by RecyclerView to display the data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.
Note that unlike android.widget.ListView, RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use getBindingAdapterPosition which will have the updated adapter position. Override onBindViewHolder instead if Adapter can handle efficient partial bind.
| Parameters | |
|---|---|
RecyclerView.ViewHolder holder |
The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. |
int position |
The position of the item within the adapter's data set. |
onBindViewHolder
public final void onBindViewHolder(
RecyclerView.ViewHolder holder,
int position,
List payloads
)
Called by RecyclerView to display the data at the specified position. This method should update the contents of the itemView to reflect the item at the given position.
Note that unlike android.widget.ListView, RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the position parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use getBindingAdapterPosition which will have the updated adapter position.
Partial bind vs full bind:
The payloads parameter is a merge list from notifyItemChanged or notifyItemRangeChanged. If the payloads list is not empty, the ViewHolder is currently bound to old data and Adapter may run an efficient partial update using the payload info. If the payload is empty, Adapter must run a full bind. Adapter should not assume that the payload passed in notify methods will be received by onBindViewHolder(). For example when the view is not attached to the screen, the payload in notifyItemChange() will be simply dropped.
| Parameters | |
|---|---|
RecyclerView.ViewHolder holder |
The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. |
int position |
The position of the item within the adapter's data set. |
List payloads |
A non-null list of merged payloads. Can be empty list if requires full update. |
onCreateViewHolder
public final RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
View.OnFocusChangeListener that assigned in onCreateViewHolder may be chained, user should never change View.OnFocusChangeListener after that.
onFailedToRecycleView
public final boolean onFailedToRecycleView(RecyclerView.ViewHolder holder)
Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state. Upon receiving this callback, Adapter can clear the animation(s) that effect the View's transient state and return true so that the View can be recycled. Keep in mind that the View in question is already removed from the RecyclerView.
In some cases, it is acceptable to recycle a View although it has transient state. Most of the time, this is a case where the transient state will be cleared in onBindViewHolder call when View is rebound to a new position. For this reason, RecyclerView leaves the decision to the Adapter and uses the return value of this method to decide whether the View should be recycled or not.
Note that when all animations are created by RecyclerView.ItemAnimator, you should never receive this callback because RecyclerView keeps those Views as children until their animations are complete. This callback is useful when children of the item views create animations which may not be easy to implement using an ItemAnimator.
You should never fix this issue by calling holder.itemView.setHasTransientState(false); unless you've previously called holder.itemView.setHasTransientState(true);. Each View.setHasTransientState(true) call must be matched by a View.setHasTransientState(false) call, otherwise, the state of the View may become inconsistent. You should always prefer to end or cancel animations that are triggering the transient state instead of handling it manually.
| Parameters | |
|---|---|
RecyclerView.ViewHolder holder |
The ViewHolder containing the View that could not be recycled due to its transient state. |
| Returns | |
|---|---|
boolean |
True if the View should be recycled, false otherwise. Note that if this method returns |
onViewAttachedToWindow
public final void onViewAttachedToWindow(RecyclerView.ViewHolder holder)
Called when a view created by this adapter 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 | |
|---|---|
RecyclerView.ViewHolder holder |
Holder of the view being attached |
onViewDetachedFromWindow
public final void onViewDetachedFromWindow(RecyclerView.ViewHolder holder)
Called when a view created by this adapter has been detached from its window.
Becoming detached from the window is not necessarily a permanent condition; the consumer of an Adapter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.
| Parameters | |
|---|---|
RecyclerView.ViewHolder holder |
Holder of the view being detached |
onViewRecycled
public final void onViewRecycled(RecyclerView.ViewHolder holder)
Called when a view created by this adapter has been recycled.
A view is recycled when a LayoutManager decides that it no longer needs to be attached to its parent RecyclerView. This can be because it has fallen out of visibility or a set of cached views represented by views still attached to the parent RecyclerView. If an item view has large or expensive data bound to it such as large bitmaps, this may be a good place to release those resources.
RecyclerView calls this method right before clearing ViewHolder's internal data and sending it to RecycledViewPool. This way, if ViewHolder was holding valid information before being recycled, you can call getBindingAdapterPosition to get its adapter position.
| Parameters | |
|---|---|
RecyclerView.ViewHolder holder |
The ViewHolder for the view being recycled |
setAdapterListener
public void setAdapterListener(ItemBridgeAdapter.AdapterListener listener)
Sets the AdapterListener.
setPresenter
public void setPresenter(PresenterSelector presenterSelector)
Changes Presenter that creates and binds the view.
| Parameters | |
|---|---|
PresenterSelector presenterSelector |
Presenter that creates and binds the view. |
setPresenterMapper
public void setPresenterMapper(ArrayList<Presenter> presenters)
Sets the presenter mapper array.
setWrapper
public void setWrapper(ItemBridgeAdapter.Wrapper wrapper)
Sets the Wrapper.
Protected methods
onAddPresenter
protected void onAddPresenter(Presenter presenter, int type)
Called when presenter is added to Adapter.
onAttachedToWindow
protected void onAttachedToWindow(ItemBridgeAdapter.ViewHolder viewHolder)
Called when ViewHolder has been attached to window.
onBind
protected void onBind(ItemBridgeAdapter.ViewHolder viewHolder)
Called when ViewHolder has been bound to data.
onCreate
protected void onCreate(ItemBridgeAdapter.ViewHolder viewHolder)
Called when ViewHolder is created.
onDetachedFromWindow
protected void onDetachedFromWindow(ItemBridgeAdapter.ViewHolder viewHolder)
Called when ViewHolder has been detached from window.
onUnbind
protected void onUnbind(ItemBridgeAdapter.ViewHolder viewHolder)
Called when ViewHolder has been unbound from data.