Adapter

Base class for an Adapter

Adapters provide a binding from an app-specific data set to views that are displayed within a RecyclerView.

Parameters

<VH>

A class that extends ViewHolder that will be used by the adapter.

Inheritors

Constructors

Link copied to clipboard
constructor()

Types

Link copied to clipboard
Defines how this Adapter wants to restore its state after a view reconstruction (e.g.

Functions

Link copied to clipboard
fun bindViewHolder(@NonNull holder: @NonNull VH, position: Int)
This method internally calls onBindViewHolder to update the ViewHolder contents with the item at the given position and also sets up some private fields to be used by RecyclerView.
Link copied to clipboard
@NonNull
fun createViewHolder(@NonNull parent: @NonNull ViewGroup, viewType: Int): @NonNull VH
This method calls onCreateViewHolder to create a new ViewHolder and initializes some private fields to be used by RecyclerView.
Link copied to clipboard
open fun findRelativeAdapterPositionIn(@NonNull adapter: @NonNull RecyclerView.Adapter<out RecyclerView.ViewHolder>, @NonNull viewHolder: @NonNull RecyclerView.ViewHolder, localPosition: Int): Int
Returns the position of the given ViewHolder in the given Adapter.
Link copied to clipboard
abstract fun getItemCount(): Int
Returns the total number of items in the data set held by the adapter.
Link copied to clipboard
open fun getItemId(position: Int): Long
Return the stable ID for the item at position.
Link copied to clipboard
open fun getItemViewType(position: Int): Int
Return the view type of the item at position for the purposes of view recycling.
Link copied to clipboard
Returns when this Adapter wants to restore the state.
Link copied to clipboard
Returns true if one or more observers are attached to this adapter.
Link copied to clipboard
Returns true if this adapter publishes a unique long value that can act as a key for the item at a given position in the data set.
Link copied to clipboard
Notify any registered observers that the data set has changed.
Link copied to clipboard
fun notifyItemChanged(position: Int)
Notify any registered observers that the item at position has changed.
fun notifyItemChanged(position: Int, @Nullable payload: @Nullable Any)
Notify any registered observers that the item at position has changed with an optional payload object.
Link copied to clipboard
fun notifyItemInserted(position: Int)
Notify any registered observers that the item reflected at position has been newly inserted.
Link copied to clipboard
fun notifyItemMoved(fromPosition: Int, toPosition: Int)
Notify any registered observers that the item reflected at fromPosition has been moved to toPosition.
Link copied to clipboard
fun notifyItemRangeChanged(positionStart: Int, itemCount: Int)
fun notifyItemRangeChanged(positionStart: Int, itemCount: Int, @Nullable payload: @Nullable Any)
Notify any registered observers that the itemCount items starting at position positionStart have changed.
Link copied to clipboard
fun notifyItemRangeInserted(positionStart: Int, itemCount: Int)
Notify any registered observers that the currently reflected itemCount items starting at positionStart have been newly inserted.
Link copied to clipboard
fun notifyItemRangeRemoved(positionStart: Int, itemCount: Int)
Notify any registered observers that the itemCount items previously located at positionStart have been removed from the data set.
Link copied to clipboard
fun notifyItemRemoved(position: Int)
Notify any registered observers that the item previously located at position has been removed from the data set.
Link copied to clipboard
open fun onAttachedToRecyclerView(@NonNull recyclerView: @NonNull RecyclerView)
Called by RecyclerView when it starts observing this Adapter.
Link copied to clipboard
abstract fun onBindViewHolder(@NonNull holder: @NonNull VH, position: Int)
open fun onBindViewHolder(@NonNull holder: @NonNull VH, position: Int, @NonNull payloads: @NonNull List<Any>)
Called by RecyclerView to display the data at the specified position.
Link copied to clipboard
@NonNull
abstract fun onCreateViewHolder(@NonNull parent: @NonNull ViewGroup, viewType: Int): @NonNull VH
Called when RecyclerView needs a new ViewHolder of the given type to represent an item.
Link copied to clipboard
open fun onDetachedFromRecyclerView(@NonNull recyclerView: @NonNull RecyclerView)
Called by RecyclerView when it stops observing this Adapter.
Link copied to clipboard
open fun onFailedToRecycleView(@NonNull holder: @NonNull VH): Boolean
Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state.
Link copied to clipboard
open fun onViewAttachedToWindow(@NonNull holder: @NonNull VH)
Called when a view created by this adapter has been attached to a window.
Link copied to clipboard
open fun onViewDetachedFromWindow(@NonNull holder: @NonNull VH)
Called when a view created by this adapter has been detached from its window.
Link copied to clipboard
open fun onViewRecycled(@NonNull holder: @NonNull VH)
Called when a view created by this adapter has been recycled.
Link copied to clipboard
open fun registerAdapterDataObserver(@NonNull observer: @NonNull RecyclerView.AdapterDataObserver)
Register a new observer to listen for data changes.
Link copied to clipboard
Link copied to clipboard
open fun setHasStableIds(hasStableIds: Boolean)
Indicates whether each item in the data set can be represented with a unique identifier of type java.lang.Long.
Link copied to clipboard
Sets the state restoration strategy for the Adapter.
Link copied to clipboard
open fun unregisterAdapterDataObserver(@NonNull observer: @NonNull RecyclerView.AdapterDataObserver)
Unregister an observer currently listening for data changes.