added in version 22.1.0
belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1

RecyclerView.ViewHolder

public static abstract class RecyclerView.ViewHolder
extends Object

java.lang.Object
   ↳ android.support.v7.widget.RecyclerView.ViewHolder
Known Direct Subclasses


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 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

Summary

Fields

public final View itemView

Public constructors

RecyclerView.ViewHolder(View itemView)

Public methods

final int getAdapterPosition()

Returns the Adapter position of the item represented by this ViewHolder.

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 was deprecated in API level 22.1.0. This method is deprecated because its meaning is ambiguous due to the async handling of adapter updates. Please use getLayoutPosition() or getAdapterPosition() 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