Android 12 Developer Preview is here! Try it out, and give us your feedback!

Adapter

abstract class Adapter<VH : RecyclerView.ViewHolder!>
kotlin.Any
   ↳ androidx.recyclerview.widget.RecyclerView.Adapter

Base class for an Adapter

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

Summary

Nested classes

Defines how this Adapter wants to restore its state after a view reconstruction (e.g. configuration change).

Public constructors

Base class for an Adapter

Public methods
Unit
bindViewHolder(@NonNull holder: VH, position: Int)

This method internally calls onBindViewHolder(ViewHolder, int) to update the ViewHolder contents with the item at the given position and also sets up some private fields to be used by RecyclerView.

VH
createViewHolder(@NonNull parent: ViewGroup, viewType: Int)

This method calls onCreateViewHolder(ViewGroup, int) to create a new ViewHolder and initializes some private fields to be used by RecyclerView.

open Int
findRelativeAdapterPositionIn(@NonNull adapter: RecyclerView.Adapter<out RecyclerView.ViewHolder!>, @NonNull viewHolder: RecyclerView.ViewHolder, localPosition: Int)

Returns the position of the given ViewHolder in the given Adapter.

abstract Int

Returns the total number of items in the data set held by the adapter.

open Long
getItemId(position: Int)

Return the stable ID for the item at position.

open Int
getItemViewType(position: Int)

Return the view type of the item at position for the purposes of view recycling.

RecyclerView.Adapter.StateRestorationPolicy

Returns when this Adapter wants to restore the state.

Boolean

Returns true if one or more observers are attached to this adapter.

Boolean

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.

Unit

Notify any registered observers that the data set has changed.

Unit

Notify any registered observers that the item at position has changed.

Unit
notifyItemChanged(position: Int, @Nullable payload: Any?)

Notify any registered observers that the item at position has changed with an optional payload object.

Unit

Notify any registered observers that the item reflected at position has been newly inserted.

Unit
notifyItemMoved(fromPosition: Int, toPosition: Int)

Notify any registered observers that the item reflected at fromPosition has been moved to toPosition.

Unit
notifyItemRangeChanged(positionStart: Int, itemCount: Int)

Notify any registered observers that the