# RecyclerView.Adapter

# RecyclerView.Adapter

Artifact:[androidx.recyclerview:recyclerview](https://developer.android.com/jetpack/androidx/releases/recyclerview)  
[View Source](https://cs.android.com/search?q=file:androidx/recyclerview/widget/RecyclerView.java+class:androidx.recyclerview.widget.RecyclerView.Adapter)  
Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter "View this page in Java")

<br />

```
abstract class RecyclerView.Adapter<VH : RecyclerView.ViewHolder?>
```

<br />

Known direct subclasses  
[ConcatAdapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter),[FragmentStateAdapter](https://developer.android.com/reference/kotlin/androidx/viewpager2/adapter/FragmentStateAdapter),[ItemBridgeAdapter](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemBridgeAdapter),[LeanbackListPreferenceDialogFragment.AdapterMulti](https://developer.android.com/reference/kotlin/androidx/leanback/preference/LeanbackListPreferenceDialogFragment.AdapterMulti),[LeanbackListPreferenceDialogFragment.AdapterSingle](https://developer.android.com/reference/kotlin/androidx/leanback/preference/LeanbackListPreferenceDialogFragment.AdapterSingle),[ListAdapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ListAdapter),[LoadStateAdapter](https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter),[PagedListAdapter](https://developer.android.com/reference/kotlin/androidx/paging/PagedListAdapter),[PagingDataAdapter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter)  

|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [ConcatAdapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter)                                                                           | An[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)implementation that presents the contents of multiple adapters in sequence.                                                                                                                                                                                |
| [FragmentStateAdapter](https://developer.android.com/reference/kotlin/androidx/viewpager2/adapter/FragmentStateAdapter)                                                              | Similar in behavior to[FragmentStatePagerAdapter](https://developer.android.com/reference/kotlin/androidx/fragment/app/FragmentStatePagerAdapter)                                                                                                                                                                                                                       |
| [ItemBridgeAdapter](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ItemBridgeAdapter)                                                                       | Bridge from[Presenter](https://developer.android.com/reference/kotlin/androidx/leanback/widget/Presenter)to[RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter).                                                                                                                                    |
| [LeanbackListPreferenceDialogFragment.AdapterMulti](https://developer.android.com/reference/kotlin/androidx/leanback/preference/LeanbackListPreferenceDialogFragment.AdapterMulti)   | **This class is deprecated.** Ue LeanbackListPreferenceDialogFragmentCompat. <br />                                                                                                                                                                                                                                                                                     |
| [LeanbackListPreferenceDialogFragment.AdapterSingle](https://developer.android.com/reference/kotlin/androidx/leanback/preference/LeanbackListPreferenceDialogFragment.AdapterSingle) | **This class is deprecated.** Use LeanbackListPreferenceDialogFragmentCompat. <br />                                                                                                                                                                                                                                                                                    |
| [ListAdapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ListAdapter)                                                                               | [RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)base class for presenting List data in a[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView), including computing diffs between Lists on a background thread.                               |
| [LoadStateAdapter](https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter)                                                                                  | Adapter for displaying a RecyclerView item based on[LoadState](https://developer.android.com/reference/kotlin/androidx/paging/LoadState), such as a loading spinner, or a retry error button.                                                                                                                                                                           |
| [PagedListAdapter](https://developer.android.com/reference/kotlin/androidx/paging/PagedListAdapter)                                                                                  | **This class is deprecated.**PagedListAdapter is deprecated and has been replaced by PagingDataAdapter                                                                                                                                                                                                                                                                  |
| [PagingDataAdapter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter)                                                                                | [RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)base class for presenting paged data from[PagingData](https://developer.android.com/reference/kotlin/androidx/paging/PagingData)s in a[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView). |

*** ** * ** ***

Base class for an Adapter

Adapters provide a binding from an app-specific data set to views that are displayed within a[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView).  

|                                                                 Parameters                                                                 |
|--------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------|
| `<VH : `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`?>` | A class that extends ViewHolder that will be used by the adapter. |

## Summary

|                                                                                                                                      ### Nested types                                                                                                                                      |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `enum `[RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy) Defines how this Adapter wants to restore its state after a view reconstruction (e.g. configuration change). |

|                                                  ### Public constructors                                                  |
|---------------------------------------------------------------------------------------------------------------------------|
| [Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#Adapter())`()` |

|                                                                          ### Public functions                                                                          |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [bindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#bindViewHolder(VH,int))`(holder: VH, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` This method internally calls[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int))to update the[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)contents with the item at the given position and also sets up some private fields to be used by RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `VH`                                                                                                                                                                   | [createViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#createViewHolder(android.view.ViewGroup,int))`(parent: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)`, viewType: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` This method calls[onCreateViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onCreateViewHolder(android.view.ViewGroup,int))to create a new[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)and initializes some private fields to be used by RecyclerView.                                                                                                                                                                                                                                                                                                                                                                                                          |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                            | [findRelativeAdapterPositionIn](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#findRelativeAdapterPositionIn(androidx.recyclerview.widget.RecyclerView.Adapter<? extends androidx.recyclerview.widget.RecyclerView.ViewHolder>,androidx.recyclerview.widget.RecyclerView.ViewHolder,int))`(` ` adapter: `[RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)`<`[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`!>,` ` viewHolder: `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`,` ` localPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) `)` Returns the position of the given[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)in the given[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter). |
| `abstract `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                 | [getItemCount](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemCount())`()` Returns the total number of items in the data set held by the adapter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                          | [getItemId](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemId(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Return the stable ID for the item at`position`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                            | [getItemViewType](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemViewType(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Return the view type of the item at`position`for the purposes of view recycling.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy) | [getStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getStateRestorationPolicy())`()` Returns when this Adapter wants to restore the state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                    | [hasObservers](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#hasObservers())`()` Returns true if one or more observers are attached to this adapter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                    | [hasStableIds](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#hasStableIds())`()` 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](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyDataSetChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyDataSetChanged())`()` Notify any registered observers that the data set has changed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Notify any registered observers that the item at`position`has changed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int,java.lang.Object))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, payload: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)` Notify any registered observers that the item at`position`has changed with an optional payload object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemInserted](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemInserted(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Notify any registered observers that the item reflected at`position`has been newly inserted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemMoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemMoved(int,int))`(fromPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, toPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Notify any registered observers that the item reflected at`fromPosition`has been moved to`toPosition`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemRangeChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int))`(positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Notify any registered observers that the`itemCount`items starting at position`positionStart`have changed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemRangeChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int,java.lang.Object))`(positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, payload: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?)` Notify any registered observers that the`itemCount`items starting at position`positionStart`have changed.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemRangeInserted](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeInserted(int,int))`(positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Notify any registered observers that the currently reflected`itemCount`items starting at`positionStart`have been newly inserted.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemRangeRemoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeRemoved(int,int))`(positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Notify any registered observers that the`itemCount`items previously located at`positionStart`have been removed from the data set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [notifyItemRemoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRemoved(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Notify any registered observers that the item previously located at`position`has been removed from the data set.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [onAttachedToRecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onAttachedToRecyclerView(androidx.recyclerview.widget.RecyclerView))`(recyclerView: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`)` Called by RecyclerView when it starts observing this Adapter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                               | [onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int))`(holder: VH, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called by RecyclerView to display the data at the specified position.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>))`(holder: VH, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, payloads: (`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!>)` Called by RecyclerView to display the data at the specified position.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `abstract VH`                                                                                                                                                          | [onCreateViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onCreateViewHolder(android.view.ViewGroup,int))`(parent: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)`, viewType: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when RecyclerView needs a new[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)of the given type to represent an item.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [onDetachedFromRecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onDetachedFromRecyclerView(androidx.recyclerview.widget.RecyclerView))`(recyclerView: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`)` Called by RecyclerView when it stops observing this Adapter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                    | [onFailedToRecycleView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onFailedToRecycleView(VH))`(holder: VH)` Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [onViewAttachedToWindow](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onViewAttachedToWindow(VH))`(holder: VH)` Called when a view created by this adapter has been attached to a window.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [onViewDetachedFromWindow](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onViewDetachedFromWindow(VH))`(holder: VH)` Called when a view created by this adapter has been detached from its window.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [onViewRecycled](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onViewRecycled(VH))`(holder: VH)` Called when a view created by this adapter has been recycled.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [registerAdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#registerAdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver))`(observer: `[RecyclerView.AdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.AdapterDataObserver)`)` Register a new observer to listen for data changes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [setHasStableIds](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setHasStableIds(boolean))`(hasStableIds: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Indicates whether each item in the data set can be represented with a unique identifier of type[java.lang.Long](https://developer.android.com/reference/java/lang/Long.html).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [setStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy))`(` ` strategy: `[RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy) `)` Sets the state restoration strategy for the Adapter.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                          | [unregisterAdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#unregisterAdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver))`(` ` observer: `[RecyclerView.AdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.AdapterDataObserver) `)` Unregister an observer currently listening for data changes.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |

## Public constructors

### Adapter

Added in 1.0.0  

```
Adapter()
```  

## Public functions

### bindViewHolder

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun bindViewHolder(holder: VH, position: Int): Unit
```

This method internally calls[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int))to update the[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)contents with the item at the given position and also sets up some private fields to be used by RecyclerView. Adapters that merge other adapters should use[bindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#bindViewHolder(VH,int))when calling nested adapters so that RecyclerView can track which adapter bound the[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)to return the correct position from[getBindingAdapterPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapterPosition())method. They should also override the[findRelativeAdapterPositionIn](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#findRelativeAdapterPositionIn(androidx.recyclerview.widget.RecyclerView.Adapter<? extends androidx.recyclerview.widget.RecyclerView.ViewHolder>,androidx.recyclerview.widget.RecyclerView.ViewHolder,int))method.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|---------------------------------------------------------|
| `holder: VH`                                                                            | The view holder whose contents should be updated        |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The position of the holder with respect to this adapter |

|                                                                   See also                                                                    |
|-----------------------------------------------------------------------------------------------------------------------------------------------|---|
| [onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int)) |   |

### createViewHolder

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun createViewHolder(parent: ViewGroup, viewType: Int): VH
```

This method calls[onCreateViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onCreateViewHolder(android.view.ViewGroup,int))to create a new[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)and initializes some private fields to be used by RecyclerView.  

|                                                                               See also                                                                                |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [onCreateViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onCreateViewHolder(android.view.ViewGroup,int)) |   |

### findRelativeAdapterPositionIn

Added in[1.2.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.2.0)  

```
fun findRelativeAdapterPositionIn(
    adapter: RecyclerView.Adapter<RecyclerView.ViewHolder!>,
    viewHolder: RecyclerView.ViewHolder,
    localPosition: Int
): Int
```

Returns the position of the given[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)in the given[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter). If the given[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)is not part of this[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter),[NO_POSITION](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_POSITION())is returned.  

|                                                                                                                                Parameters                                                                                                                                |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `adapter: `[RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)`<`[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`!>` | The adapter which is a sub adapter of this adapter or itself.                                                                                                                                                                                                 |
| `viewHolder: `[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)                                                                                                                             | The ViewHolder whose local position in the given adapter will be returned.                                                                                                                                                                                    |
| `localPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                             | The position of the given[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)in this[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter). |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The local position of the given[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)in this[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)or[NO_POSITION](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_POSITION())if the[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)is not bound to an item or the given[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)is not part of this Adapter (if this Adapter merges other adapters). |

### getItemCount

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
abstract fun getItemCount(): Int
```

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

|                                   Returns                                   |
|-----------------------------------------------------------------------------|--------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The total number of items in this adapter. |

### getItemId

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun getItemId(position: Int): Long
```

Return the stable ID for the item at`position`. If[hasStableIds](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#hasStableIds())would return false this method should return[NO_ID](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_ID()). The default implementation of this method returns[NO_ID](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_ID()).  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|---------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Adapter position to query |

|                                    Returns                                    |
|-------------------------------------------------------------------------------|---------------------------------------|
| [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) | the stable ID of the item at position |

### getItemViewType

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun getItemViewType(position: Int): Int
```

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

The default implementation of this method returns 0, making the assumption of a single view type for the adapter. Unlike ListView adapters, types need not be contiguous. Consider using id resources to uniquely identify item view types.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|-------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | position to query |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | integer value identifying the type of the view needed to represent the item at`position`. Type codes need not be contiguous. |

### getStateRestorationPolicy

Added in[1.2.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.2.0)  

```
fun getStateRestorationPolicy(): RecyclerView.Adapter.StateRestorationPolicy
```

Returns when this Adapter wants to restore the state.  

|                                                                                Returns                                                                                 |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy) | The current[StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy)for this Adapter. Defaults to[ALLOW](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#ALLOW). |

|                                                                                                             See also                                                                                                              |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [setStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy)) |   |

### hasObservers

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun hasObservers(): Boolean
```

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

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if this adapter has observers |

### hasStableIds

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun hasStableIds(): 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. If that item is relocated in the data set, the ID returned for that item should be the same.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if this adapter's items have stable IDs |

### notifyDataSetChanged

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyDataSetChanged(): Unit
```

Notify any registered observers that the data set has changed.

There are two different classes of data change events, item changes and structural changes. Item changes are when a single item has its data updated but no positional changes have occurred. Structural changes are when items are inserted, removed or moved within the data set.

This event does not specify what about the data set has changed, forcing any observers to assume that all existing items and structure may no longer be valid. LayoutManagers will be forced to fully rebind and relayout all visible views.

`RecyclerView`will attempt to synthesize visible structural change events for adapters that report that they have[stable IDs](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#hasStableIds())when this method is used. This can help for the purposes of animation and visual object persistence but individual item views will still need to be rebound and relaid out.

If you are writing an adapter it will always be more efficient to use the more specific change events if you can. Rely on`notifyDataSetChanged()`as a last resort.  

|                                                                           See also                                                                           |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int))                 |   |
| [notifyItemInserted](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemInserted(int))               |   |
| [notifyItemRemoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRemoved(int))                 |   |
| [notifyItemRangeChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int))   |   |
| [notifyItemRangeInserted](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeInserted(int,int)) |   |
| [notifyItemRangeRemoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeRemoved(int,int))   |   |

### notifyItemChanged

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemChanged(position: Int): Unit
```

Notify any registered observers that the item at`position`has changed. Equivalent to calling`notifyItemChanged(position, null);`.

This is an item change event, not a structural change event. It indicates that any reflection of the data at`position`is out of date and should be updated. The item at`position`retains the same identity.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|---------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Position of the item that has changed |

|                                                                          See also                                                                          |
|------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemRangeChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int)) |   |

### notifyItemChanged

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemChanged(position: Int, payload: Any?): Unit
```

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

This is an item change event, not a structural change event. It indicates that any reflection of the data at`position`is out of date and should be updated. The item at`position`retains the same identity.

Client can optionally pass a payload for partial change. These payloads will be merged and may be passed to adapter's[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>))if the item is already represented by a ViewHolder and it will be rebound to the same ViewHolder. A notifyItemRangeChanged() with null payload will clear all existing payloads on that item and prevent future payload until[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>))is called. Adapter should not assume that the payload will always be passed to onBindViewHolder(), e.g. when the view is not attached, the payload will be simply dropped.  

|                                        Parameters                                         |
|-------------------------------------------------------------------------------------------|----------------------------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | Position of the item that has changed                    |
| `payload: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?` | Optional parameter, use null to identify a "full" update |

|                                                                          See also                                                                          |
|------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemRangeChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int)) |   |

### notifyItemInserted

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemInserted(position: Int): Unit
```

Notify any registered observers that the item reflected at`position`has been newly inserted. The item previously at`position`is now at position`position + 1`.

This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|-----------------------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Position of the newly inserted item in the data set |

|                                                                           See also                                                                           |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemRangeInserted](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeInserted(int,int)) |   |

### notifyItemMoved

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemMoved(fromPosition: Int, toPosition: Int): Unit
```

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

This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.  

|                                         Parameters                                          |
|---------------------------------------------------------------------------------------------|--------------------------------|
| `fromPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Previous position of the item. |
| `toPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | New position of the item.      |

### notifyItemRangeChanged

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemRangeChanged(positionStart: Int, itemCount: Int): Unit
```

Notify any registered observers that the`itemCount`items starting at position`positionStart`have changed. Equivalent to calling`notifyItemRangeChanged(position, itemCount, null);`.

This is an item change event, not a structural change event. It indicates that any reflection of the data in the given position range is out of date and should be updated. The items in the given range retain the same identity.  

|                                          Parameters                                          |
|----------------------------------------------------------------------------------------------|---------------------------------------------|
| `positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Position of the first item that has changed |
| `itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | Number of items that have changed           |

|                                                                   See also                                                                   |
|----------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int)) |   |

### notifyItemRangeChanged

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemRangeChanged(positionStart: Int, itemCount: Int, payload: Any?): Unit
```

Notify any registered observers that the`itemCount`items starting at position`positionStart`have changed. An optional payload can be passed to each changed item.

This is an item change event, not a structural change event. It indicates that any reflection of the data in the given position range is out of date and should be updated. The items in the given range retain the same identity.

Client can optionally pass a payload for partial change. These payloads will be merged and may be passed to adapter's[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>))if the item is already represented by a ViewHolder and it will be rebound to the same ViewHolder. A notifyItemRangeChanged() with null payload will clear all existing payloads on that item and prevent future payload until[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>))is called. Adapter should not assume that the payload will always be passed to onBindViewHolder(), e.g. when the view is not attached, the payload will be simply dropped.  

|                                          Parameters                                          |
|----------------------------------------------------------------------------------------------|----------------------------------------------------------|
| `positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Position of the first item that has changed              |
| `itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | Number of items that have changed                        |
| `payload: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?`    | Optional parameter, use null to identify a "full" update |

|                                                                   See also                                                                   |
|----------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int)) |   |

### notifyItemRangeInserted

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemRangeInserted(positionStart: Int, itemCount: Int): Unit
```

Notify any registered observers that the currently reflected`itemCount`items starting at`positionStart`have been newly inserted. The items previously located at`positionStart`and beyond can now be found starting at position`positionStart + itemCount`.

This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.  

|                                          Parameters                                          |
|----------------------------------------------------------------------------------------------|----------------------------------------------|
| `positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Position of the first item that was inserted |
| `itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | Number of items inserted                     |

|                                                                    See also                                                                    |
|------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemInserted](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemInserted(int)) |   |

### notifyItemRangeRemoved

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemRangeRemoved(positionStart: Int, itemCount: Int): Unit
```

Notify any registered observers that the`itemCount`items previously located at`positionStart`have been removed from the data set. The items previously located at and after`positionStart + itemCount`may now be found at`oldPosition - itemCount`.

This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.  

|                                          Parameters                                          |
|----------------------------------------------------------------------------------------------|------------------------------------------------------|
| `positionStart: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Previous position of the first item that was removed |
| `itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)     | Number of items removed from the data set            |

### notifyItemRemoved

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun notifyItemRemoved(position: Int): Unit
```

Notify any registered observers that the item previously located at`position`has been removed from the data set. The items previously located at and after`position`may now be found at`oldPosition - 1`.

This is a structural change event. Representations of other existing items in the data set are still considered up to date and will not be rebound, though their positions may be altered.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|------------------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Position of the item that has now been removed |

|                                                                          See also                                                                          |
|------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [notifyItemRangeRemoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeRemoved(int,int)) |   |

### onAttachedToRecyclerView

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun onAttachedToRecyclerView(recyclerView: RecyclerView): Unit
```

Called by RecyclerView when it starts observing this Adapter.

Keep in mind that same adapter may be observed by multiple RecyclerViews.  

|                                                        Parameters                                                        |
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| `recyclerView: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView) | The RecyclerView instance which started observing this adapter. |

|                                                                                               See also                                                                                               |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [onDetachedFromRecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onDetachedFromRecyclerView(androidx.recyclerview.widget.RecyclerView)) |   |

### onBindViewHolder

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
abstract fun onBindViewHolder(holder: VH, position: Int): Unit
```

Called by RecyclerView to display the data at the specified position. This method should update the contents of the[itemView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#itemView())to reflect the item at the given position.

Note that unlike[android.widget.ListView](https://developer.android.com/reference/android/widget/ListView.html), RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the`position`parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use[getBindingAdapterPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapterPosition())which will have the updated adapter position. Override[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>))instead if Adapter can handle efficient partial bind.  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| `holder: VH`                                                                            | The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The position of the item within the adapter's data set.                                                             |

### onBindViewHolder

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun onBindViewHolder(holder: VH, position: Int, payloads: (Mutable)List<Any!>): Unit
```

Called by RecyclerView to display the data at the specified position. This method should update the contents of the[itemView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#itemView())to reflect the item at the given position.

Note that unlike[android.widget.ListView](https://developer.android.com/reference/android/widget/ListView.html), RecyclerView will not call this method again if the position of the item changes in the data set unless the item itself is invalidated or the new position cannot be determined. For this reason, you should only use the`position`parameter while acquiring the related data item inside this method and should not keep a copy of it. If you need the position of an item later on (e.g. in a click listener), use[getBindingAdapterPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapterPosition())which will have the updated adapter position.

Partial bind vs full bind:

The payloads parameter is a merge list from[notifyItemChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int,java.lang.Object))or[notifyItemRangeChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int,java.lang.Object)). If the payloads list is not empty, the ViewHolder is currently bound to old data and Adapter may run an efficient partial update using the payload info. If the payload is empty, Adapter must run a full bind. Adapter should not assume that the payload passed in notify methods will be received by onBindViewHolder(). For example when the view is not attached to the screen, the payload in notifyItemChange() will be simply dropped.  

|                                                                                                                                           Parameters                                                                                                                                            |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| `holder: VH`                                                                                                                                                                                                                                                                                    | The ViewHolder which should be updated to represent the contents of the item at the given position in the data set. |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                                         | The position of the item within the adapter's data set.                                                             |
| `payloads: (`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)`)`[List](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html)`<`[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!>` | A non-null list of merged payloads. Can be empty list if requires full update.                                      |

### onCreateViewHolder

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
abstract fun onCreateViewHolder(parent: ViewGroup, viewType: Int): VH
```

Called when RecyclerView needs a new[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)of the given type to represent an item.

This new ViewHolder should be constructed with a new View that can represent the items of the given type. You can either create a new View manually or inflate it from an XML layout file.

The new ViewHolder will be used to display items of the adapter using[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>)). Since it will be re-used to display different items in the data set, it is a good idea to cache references to sub views of the View to avoid unnecessary[findViewById](https://developer.android.com/reference/android/view/View.html#findViewById(int))calls.  

|                                         Parameters                                         |
|--------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------|
| `parent: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) | The ViewGroup into which the new View will be added after it is bound to an adapter position. |
| `viewType: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)    | The view type of the new View.                                                                |

| Returns |
|---------|------------------------------------------------------------|
| `VH`    | A new ViewHolder that holds a View of the given view type. |

|                                                                   See also                                                                    |
|-----------------------------------------------------------------------------------------------------------------------------------------------|---|
| [getItemViewType](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemViewType(int))      |   |
| [onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int)) |   |

### onDetachedFromRecyclerView

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun onDetachedFromRecyclerView(recyclerView: RecyclerView): Unit
```

Called by RecyclerView when it stops observing this Adapter.  

|                                                        Parameters                                                        |
|--------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------|
| `recyclerView: `[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView) | The RecyclerView instance which stopped observing this adapter. |

|                                                                                             See also                                                                                             |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [onAttachedToRecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onAttachedToRecyclerView(androidx.recyclerview.widget.RecyclerView)) |   |

### onFailedToRecycleView

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun onFailedToRecycleView(holder: VH): Boolean
```

Called by the RecyclerView if a ViewHolder created by this Adapter cannot be recycled due to its transient state. Upon receiving this callback, Adapter can clear the animation(s) that effect the View's transient state and return`true`so that the View can be recycled. Keep in mind that the View in question is already removed from the RecyclerView.

In some cases, it is acceptable to recycle a View although it has transient state. Most of the time, this is a case where the transient state will be cleared in[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int))call when View is rebound to a new position. For this reason, RecyclerView leaves the decision to the Adapter and uses the return value of this method to decide whether the View should be recycled or not.

Note that when all animations are created by[RecyclerView.ItemAnimator](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemAnimator), you should never receive this callback because RecyclerView keeps those Views as children until their animations are complete. This callback is useful when children of the item views create animations which may not be easy to implement using an[ItemAnimator](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ItemAnimator).

You should*never* fix this issue by calling`holder.itemView.setHasTransientState(false);`unless you've previously called`holder.itemView.setHasTransientState(true);`. Each`View.setHasTransientState(true)`call must be matched by a`View.setHasTransientState(false)`call, otherwise, the state of the View may become inconsistent. You should always prefer to end or cancel animations that are triggering the transient state instead of handling it manually.  

|  Parameters  |
|--------------|-------------------------------------------------------------------------------------------|
| `holder: VH` | The ViewHolder containing the View that could not be recycled due to its transient state. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if the View should be recycled, false otherwise. Note that if this method returns`true`, RecyclerView*will ignore* the transient state of the View and recycle it regardless. If this method returns`false`, RecyclerView will check the View's transient state again before giving a final decision. Default implementation returns false. |

### onViewAttachedToWindow

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun onViewAttachedToWindow(holder: VH): Unit
```

Called when a view created by this adapter has been attached to a window.

This can be used as a reasonable signal that the view is about to be seen by the user. If the adapter previously freed any resources in[onViewDetachedFromWindow](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onViewDetachedFromWindow(VH))those resources should be restored here.  

|  Parameters  |
|--------------|-----------------------------------|
| `holder: VH` | Holder of the view being attached |

### onViewDetachedFromWindow

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun onViewDetachedFromWindow(holder: VH): Unit
```

Called when a view created by this adapter has been detached from its window.

Becoming detached from the window is not necessarily a permanent condition; the consumer of an Adapter's views may choose to cache views offscreen while they are not visible, attaching and detaching them as appropriate.  

|  Parameters  |
|--------------|-----------------------------------|
| `holder: VH` | Holder of the view being detached |

### onViewRecycled

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun onViewRecycled(holder: VH): Unit
```

Called when a view created by this adapter has been recycled.

A view is recycled when a[LayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager)decides that it no longer needs to be attached to its parent[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView). This can be because it has fallen out of visibility or a set of cached views represented by views still attached to the parent RecyclerView. If an item view has large or expensive data bound to it such as large bitmaps, this may be a good place to release those resources.

RecyclerView calls this method right before clearing ViewHolder's internal data and sending it to RecycledViewPool. This way, if ViewHolder was holding valid information before being recycled, you can call[getBindingAdapterPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapterPosition())to get its adapter position.  

|  Parameters  |
|--------------|--------------------------------------------|
| `holder: VH` | The ViewHolder for the view being recycled |

### registerAdapterDataObserver

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun registerAdapterDataObserver(observer: RecyclerView.AdapterDataObserver): Unit
```

Register a new observer to listen for data changes.

The adapter may publish a variety of events describing specific changes. Not all adapters may support all change types and some may fall back to a generic["something changed"](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.AdapterDataObserver#onChanged())event if more specific data is not available.

Components registering observers with an adapter are responsible for[unregistering](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#unregisterAdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver))those observers when finished.  

|                                                                          Parameters                                                                          |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
| `observer: `[RecyclerView.AdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.AdapterDataObserver) | Observer to register |

|                                                                                                            See also                                                                                                            |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [unregisterAdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#unregisterAdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver)) |   |

### setHasStableIds

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun setHasStableIds(hasStableIds: Boolean): Unit
```

Indicates whether each item in the data set can be represented with a unique identifier of type[java.lang.Long](https://developer.android.com/reference/java/lang/Long.html).  

|                                             Parameters                                              |
|-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------|
| `hasStableIds: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | Whether items in data set have unique identifiers or not. |

|                                                            See also                                                             |
|---------------------------------------------------------------------------------------------------------------------------------|---|
| [hasStableIds](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#hasStableIds()) |   |
| [getItemId](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemId(int))    |   |

### setStateRestorationPolicy

Added in[1.2.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.2.0)  

```
fun setStateRestorationPolicy(
    strategy: RecyclerView.Adapter.StateRestorationPolicy
): Unit
```

Sets the state restoration strategy for the Adapter. By default, it is set to[ALLOW](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#ALLOW)which means RecyclerView expects any set Adapter to be immediately capable of restoring the RecyclerView's saved scroll position.

This behaviour might be undesired if the Adapter's data is loaded asynchronously, and thus unavailable during initial layout (e.g. after Activity rotation). To avoid losing scroll position, you can change this to be either[PREVENT_WHEN_EMPTY](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT_WHEN_EMPTY)or[PREVENT](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT). Note that the former means your RecyclerView will restore state as soon as Adapter has 1 or more items while the latter requires you to call[setStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy))with either[ALLOW](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#ALLOW)or[PREVENT_WHEN_EMPTY](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT_WHEN_EMPTY)again when the Adapter is ready to restore its state.

RecyclerView will still layout even when State restoration is disabled. The behavior of how State is restored is up to the[LayoutManager](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager). All default LayoutManagers will override current state with restored state when state restoration happens (unless an explicit call to[scrollToPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.LayoutManager#scrollToPosition(int))is made).

Calling this method after state is restored will not have any effect other than changing the return value of[getStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getStateRestorationPolicy()).  

|                                                                                     Parameters                                                                                     |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------|
| `strategy: `[RecyclerView.Adapter.StateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy) | The saved state restoration strategy for this Adapter. |

|                                                                         See also                                                                          |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [getStateRestorationPolicy](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getStateRestorationPolicy()) |   |

### unregisterAdapterDataObserver

Added in[1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)  

```
fun unregisterAdapterDataObserver(
    observer: RecyclerView.AdapterDataObserver
): Unit
```

Unregister an observer currently listening for data changes.

The unregistered observer will no longer receive events about changes to the adapter.  

|                                                                          Parameters                                                                          |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------------|
| `observer: `[RecyclerView.AdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.AdapterDataObserver) | Observer to unregister |

|                                                                                                          See also                                                                                                          |
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [registerAdapterDataObserver](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#registerAdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver)) |   |