T - The type of the data sourcepublic abstract class AdapterDelegate<T>
extends java.lang.Object
RecyclerView.Adapter lifecycle.
This "hook in" mechanism is provided by AdapterDelegatesManager and that is the
component
you have to use.| Constructor and Description |
|---|
AdapterDelegate() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract boolean |
isForViewType(T items,
int position)
Called to determine whether this AdapterDelegate is the responsible for the given data
element.
|
protected abstract void |
onBindViewHolder(T items,
int position,
androidx.recyclerview.widget.RecyclerView.ViewHolder holder,
java.util.List<java.lang.Object> payloads)
Called to bind the
RecyclerView.ViewHolder to the item of the datas source set |
protected abstract androidx.recyclerview.widget.RecyclerView.ViewHolder |
onCreateViewHolder(android.view.ViewGroup parent)
Creates the
RecyclerView.ViewHolder for the given data source item |
protected boolean |
onFailedToRecycleView(androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled
due to its transient state.
|
protected void |
onViewAttachedToWindow(androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
Called when a view created by this adapter has been attached to a window.
|
protected void |
onViewDetachedFromWindow(androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
Called when a view created by this adapter has been detached from its window.
|
protected void |
onViewRecycled(androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
Called when a view created by this adapter has been recycled.
|
protected abstract boolean isForViewType(@NonNull
T items,
int position)
items - The data source of the Adapterposition - The position in the datasource@NonNull
protected abstract androidx.recyclerview.widget.RecyclerView.ViewHolder onCreateViewHolder(@NonNull
android.view.ViewGroup parent)
RecyclerView.ViewHolder for the given data source itemparent - The ViewGroup parent of the given datasourceRecyclerView.ViewHolderprotected abstract void onBindViewHolder(@NonNull
T items,
int position,
@NonNull
androidx.recyclerview.widget.RecyclerView.ViewHolder holder,
@NonNull
java.util.List<java.lang.Object> payloads)
RecyclerView.ViewHolder to the item of the datas source setitems - The data sourceposition - The position in the datasourceholder - The RecyclerView.ViewHolder to bindpayloads - A non-null list of merged payloads. Can be empty list if requires full update.protected void onViewRecycled(@NonNull
androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
A view is recycled when a RecyclerView.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 RecyclerView.ViewHolder#getAdapterPosition() to
get
its adapter position.
holder - The ViewHolder for the view being recycledprotected boolean onFailedToRecycleView(@NonNull
androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
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
RecyclerView.Adapter#onBindViewHolder(RecyclerView.ViewHolder, int) 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 RecyclerView.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.
holder - The ViewHolder containing the View that could not be recycled due to its
transient state.true, RecyclerView will ignore the transient state of
the View and recycle it regardless. If this method returns false,
RecyclerView will check the View's transient state again before giving a final decision.
Default implementation returns false.protected void onViewAttachedToWindow(@NonNull
androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
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.
holder - Holder of the view being attachedprotected void onViewDetachedFromWindow(@NonNull
androidx.recyclerview.widget.RecyclerView.ViewHolder holder)
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 an detaching them as appropriate.
holder - Holder of the view being detached