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  | 
| 
        
        
        
        final
        
        boolean | 
      isRecyclable()
       | 
| 
        
        
        
        final
        
        void | 
      setIsRecyclable(boolean recyclable)
      Informs the recycler whether this item can be recycled. | 
| 
        
        
        
        
        
        String | 
      toString()
       | 
| Inherited methods | |
|---|---|
|  From
class 
  
    java.lang.Object
  
 | |
Fields
Public constructors
RecyclerView.ViewHolder
RecyclerView.ViewHolder (View itemView)
| Parameters | |
|---|---|
| itemView | View | 
Public methods
getAdapterPosition
int getAdapterPosition ()
Returns the Adapter position of the item represented by this ViewHolder.
 Note that this might be different than the getLayoutPosition() if there are
 pending adapter updates but a new layout pass has not happened yet.
 
RecyclerView does not handle any adapter updates until the next layout traversal. This may create temporary inconsistencies between what user sees on the screen and what adapter contents have. This inconsistency is not important since it will be less than 16ms but it might be a problem if you want to use ViewHolder position to access the adapter. Sometimes, you may need to get the exact adapter position to do some actions in response to user events. In that case, you should use this method which will calculate the Adapter position of the ViewHolder.
 Note that if you've called notifyDataSetChanged(), until the
 next layout pass, the return value of this method will be NO_POSITION.
| Returns | |
|---|---|
| int | The adapter position of the item if it still exists in the adapter. NO_POSITIONif item has been removed from the adapter,notifyDataSetChanged()has been called after the last
 layout pass or the ViewHolder has already been recycled. | 
getItemId
long getItemId ()
Returns The itemId represented by this ViewHolder.
| Returns | |
|---|---|
| long | The item's id if adapter has stable ids, NO_IDotherwise | 
getItemViewType
int getItemViewType ()
| Returns | |
|---|---|
| int | The view type of this ViewHolder. | 
getLayoutPosition
int getLayoutPosition ()
Returns the position of the ViewHolder in terms of the latest layout pass.
This position is mostly used by RecyclerView components to be consistent while RecyclerView lazily processes adapter updates.
For performance and animation reasons, RecyclerView batches all adapter updates until the next layout pass. This may cause mismatches between the Adapter position of the item and the position it had in the latest layout calculations.
 LayoutManagers should always call this method while doing calculations based on item
 positions. All methods in RecyclerView.LayoutManager, RecyclerView.State,
 RecyclerView.Recycler that receive a position expect it to be the layout position
 of the item.
 
 If LayoutManager needs to call an external method that requires the adapter position of
 the item, it can use getAdapterPosition() or
 convertPreLayoutPositionToPostLayout(int).
| Returns | |
|---|---|
| int | Returns the adapter position of the ViewHolder in the latest layout pass. | 
See also:
getOldPosition
int getOldPosition ()
When LayoutManager supports animations, RecyclerView tracks 3 positions for ViewHolders to perform animations.
If a ViewHolder was laid out in the previous onLayout call, old position will keep its adapter index in the previous layout.
| Returns | |
|---|---|
| int | The previous adapter index of the Item represented by this ViewHolder or NO_POSITIONif old position does not exists or cleared (pre-layout is
 complete). | 
getPosition
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.
  
| Returns | |
|---|---|
| int | |
See also:
isRecyclable
boolean isRecyclable ()
| Returns | |
|---|---|
| boolean | true if this item is available to be recycled, false otherwise. | 
See also:
setIsRecyclable
void setIsRecyclable (boolean recyclable)
Informs the recycler whether this item can be recycled. Views which are not recyclable will not be reused for other items until setIsRecyclable() is later set to true. Calls to setIsRecyclable() should always be paired (one call to setIsRecyclabe(false) should always be matched with a later call to setIsRecyclable(true)). Pairs of calls may be nested, as the state is internally reference-counted.
| Parameters | |
|---|---|
| recyclable | boolean: Whether this item is available to be recycled. Default value
 is true. | 
See also:
toString
String toString ()
| Returns | |
|---|---|
| String | |
- Annotations
- Interfaces- ActionMenuView.OnMenuItemClickListener
- PopupMenu.OnDismissListener
- PopupMenu.OnMenuItemClickListener
- RecyclerView.ChildDrawingOrderCallback
- RecyclerView.ItemAnimator.ItemAnimatorFinishedListener
- RecyclerView.LayoutManager.LayoutPrefetchRegistry
- RecyclerView.OnChildAttachStateChangeListener
- RecyclerView.OnItemTouchListener
- RecyclerView.RecyclerListener
- RecyclerView.SmoothScroller.ScrollVectorProvider
- SearchView.OnCloseListener
- SearchView.OnQueryTextListener
- SearchView.OnSuggestionListener
- ShareActionProvider.OnShareTargetSelectedListener
- ThemedSpinnerAdapter
- Toolbar.OnMenuItemClickListener
 
- Classes- ActionMenuView
- ActionMenuView.LayoutParams
- AppCompatAutoCompleteTextView
- AppCompatButton
- AppCompatCheckBox
- AppCompatCheckedTextView
- AppCompatEditText
- AppCompatImageButton
- AppCompatImageView
- AppCompatMultiAutoCompleteTextView
- AppCompatRadioButton
- AppCompatRatingBar
- AppCompatSeekBar
- AppCompatSpinner
- AppCompatTextView
- CardView
- DefaultItemAnimator
- DividerItemDecoration
- GridLayout
- GridLayout.Alignment
- GridLayout.LayoutParams
- GridLayout.Spec
- GridLayoutManager
- GridLayoutManager.DefaultSpanSizeLookup
- GridLayoutManager.LayoutParams
- GridLayoutManager.SpanSizeLookup
- LinearLayoutCompat
- LinearLayoutCompat.LayoutParams
- LinearLayoutManager
- LinearLayoutManager.LayoutChunkResult
- LinearSmoothScroller
- LinearSnapHelper
- ListPopupWindow
- OrientationHelper
- PagerSnapHelper
- PopupMenu
- RecyclerView
- RecyclerView.Adapter
- RecyclerView.AdapterDataObserver
- RecyclerView.EdgeEffectFactory
- RecyclerView.ItemAnimator
- RecyclerView.ItemAnimator.ItemHolderInfo
- RecyclerView.ItemDecoration
- RecyclerView.LayoutManager
- RecyclerView.LayoutManager.Properties
- RecyclerView.LayoutParams
- RecyclerView.OnFlingListener
- RecyclerView.OnScrollListener
- RecyclerView.RecycledViewPool
- RecyclerView.Recycler
- RecyclerView.SimpleOnItemTouchListener
- RecyclerView.SmoothScroller
- RecyclerView.SmoothScroller.Action
- RecyclerView.State
- RecyclerView.ViewCacheExtension
- RecyclerView.ViewHolder
- RecyclerViewAccessibilityDelegate
- RecyclerViewAccessibilityDelegate.ItemDelegate
- SearchView
- ShareActionProvider
- SimpleItemAnimator
- SnapHelper
- StaggeredGridLayoutManager
- StaggeredGridLayoutManager.LayoutParams
- SwitchCompat
- ThemedSpinnerAdapter.Helper
- Toolbar
- Toolbar.LayoutParams
- Toolbar.SavedState
- TooltipCompat
 
