I - The type of the item that is managed by this AdapterDelegate. Must be a subtype of TT - The generic type of the list, in other words: List<T>VH - The type of the ViewHolderpublic abstract class AbsListItemAdapterDelegate<I extends T,T,VH extends androidx.recyclerview.widget.RecyclerView.ViewHolder> extends AdapterDelegate<java.util.List<T>>
AdapterDelegate when the underlying adapter's dataset is a List. This class helps to reduce writing boilerplate code like casting list item and casting
ViewHolder.
For instance if you have a list of animals (different kind of animals in classes like Cat, Dog
etc. assuming all have a common super class Animal) you want to display in your adapter and
you want to create a CatAdapterDelegate then this class would look like this:
{@code
class CatAdapterDelegate extends AbsListItemAdapterDelegate
| Constructor and Description |
|---|
AbsListItemAdapterDelegate() |
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
isForViewType(java.util.List<T> items,
int position)
Called to determine whether this AdapterDelegate is the responsible for the given data
element.
|
protected abstract boolean |
isForViewType(T item,
java.util.List<T> items,
int position)
Called to determine whether this AdapterDelegate is the responsible for the given item in the
list or not
element
|
protected abstract void |
onBindViewHolder(I item,
VH holder,
java.util.List<java.lang.Object> payloads)
Called to bind the
RecyclerView.ViewHolder to the item of the dataset |
protected void |
onBindViewHolder(java.util.List<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 VH |
onCreateViewHolder(android.view.ViewGroup parent)
Creates the
RecyclerView.ViewHolder for the given data source item |
onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycledprotected final boolean isForViewType(@NonNull
java.util.List<T> items,
int position)
AdapterDelegateisForViewType in class AdapterDelegate<java.util.List<T>>items - The data source of the Adapterposition - The position in the datasourceprotected final void onBindViewHolder(@NonNull
java.util.List<T> items,
int position,
@NonNull
androidx.recyclerview.widget.RecyclerView.ViewHolder holder,
@NonNull
java.util.List<java.lang.Object> payloads)
AdapterDelegateRecyclerView.ViewHolder to the item of the datas source setonBindViewHolder in class AdapterDelegate<java.util.List<T>>items - 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 abstract boolean isForViewType(@NonNull
T item,
@NonNull
java.util.List<T> items,
int position)
item - The item from the list at the given positionitems - The items from adapters datasetposition - The items position in the dataset (list)@NonNull protected abstract VH onCreateViewHolder(@NonNull android.view.ViewGroup parent)
RecyclerView.ViewHolder for the given data source itemonCreateViewHolder in class AdapterDelegate<java.util.List<T>>parent - The ViewGroup parent of the given datasource