public static abstract class RecyclerView.ViewHolder
extends Object

   ↳ androidx.recyclerview.widget.RecyclerView.ViewHolder

A ViewHolder describes an item view and metadata about its place within the RecyclerView.

RecyclerView.Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive View.findViewById(int) results.

While RecyclerView.LayoutParams belong to the RecyclerView.LayoutManager, ViewHolders belong to the adapter. Adapters should feel free to use their own custom ViewHolder implementations to store data that makes binding view contents easier. Implementations should assume that individual item views will hold strong references to ViewHolder objects and that RecyclerView instances may hold strong references to extra off-screen item views for caching purposes



public final View itemView

Public constructors

ViewHolder(View itemView)

Public methods

final int getAbsoluteAdapterPosition()

Returns the Adapter position of the item represented by this ViewHolder with respect to the RecyclerView's RecyclerView.Adapter.

final int getAdapterPosition()

This method is deprecated. This method is confusing when adapters nest other adapters. If you are calling this in the context of an Adapter, you probably want to call getBindingAdapterPosition() or if you want the position as RecyclerView sees it, you should call getAbsoluteAdapterPosition().

final Adapter<? extends RecyclerView.ViewHolder> getBindingAdapter()

Returns the RecyclerView.Adapter that last bound this RecyclerView.ViewHolder.

final int getBindingAdapterPosition()

Returns the Adapter position of the item represented by this ViewHolder with respect to the RecyclerView.Adapter that bound it.

final long getItemId()

Returns The itemId represented by this ViewHolder.

final int getItemViewType()
final int getLayoutPosition()

Returns the position of the ViewHolder in terms of the latest layout pass.

final int getOldPosition()

When LayoutManager supports animations, RecyclerView tracks 3 positions for ViewHolders to perform animations.

final int getPosition()

This method is deprecated. This method is deprecated because its meaning is ambiguous due to the async handling of adapter updates. You should use getLayoutPosition(), getBindingAdapterPosition() or getAbsoluteAdapterPosition() depending on your use case.

final boolean isRecyclable()
final void setIsRecyclable(boolean recyclable)

Informs the recycler whether this item can be recycled.

String toString()

Inherited methods



public final View itemView

Public constructors


public ViewHolder (View itemView)

itemView View