# PagingDataAdapter

Artifact: [androidx.paging:paging-runtime](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingDataAdapter.kt+class:androidx.paging.PagingDataAdapter) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- android

  ```
  abstract class PagingDataAdapter<T : Any, VH : RecyclerView.ViewHolder> : RecyclerView.Adapter<VH>
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.recyclerview.widget.RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)\<VH\> ||
|   | ↳ | [androidx.paging.PagingDataAdapter](https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter) |

*** ** * ** ***

`https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter` base class for presenting paged data from `https://developer.android.com/reference/kotlin/androidx/paging/PagingData`s in a `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView`.

This class is a convenience wrapper around `https://developer.android.com/reference/kotlin/androidx/paging/AsyncPagingDataDiffer` that implements common default behavior for item counting, and listening to update events.

To present a `https://developer.android.com/reference/kotlin/androidx/paging/Pager`, use `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html` to observe `https://developer.android.com/reference/kotlin/androidx/paging/Pager#flow()` and call `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.paging.PagingData)` whenever a new `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` is emitted.

If using RxJava and LiveData extensions on `https://developer.android.com/reference/kotlin/androidx/paging/Pager`, use the non-suspending overload of `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.paging.PagingData)`, which accepts a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`.

`https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter` listens to internal `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` loading events as `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` are loaded, and uses `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil` on a background thread to compute fine grained updates as updated content in the form of new PagingData objects are received.

*State Restoration* : To be able to restore `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView` state (e.g. scroll position) after a configuration change / application recreate, `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter` calls `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy)` with `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT` upon initialization and waits for the first page to load before allowing state restoration. Any other call to `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy)` by the application will disable this logic and will rely on the user set value.

```kotlin
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil

val USER_COMPARATOR =
    object : DiffUtil.ItemCallback<User>() {
        override fun areItemsTheSame(oldItem: User, newItem: User): Boolean =
            // User ID serves as unique ID
            oldItem.userId == newItem.userId

        override fun areContentsTheSame(oldItem: User, newItem: User): Boolean =
            // Compare full contents (note: Java users should call .equals())
            oldItem == newItem
    }

class UserAdapter : PagingDataAdapter<User, UserViewHolder>(USER_COMPARATOR) {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): UserViewHolder {
        return UserViewHolder.create(parent)
    }

    override fun onBindViewHolder(holder: UserViewHolder, position: Int) {
        val repoItem = getItem(position)
        // Note that item may be null, ViewHolder must support binding null item as placeholder
        holder.bind(repoItem)
    }
}
```

## Summary

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, VH : https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#PagingDataAdapter(androidx.recyclerview.widget.DiffUtil.ItemCallback,kotlin.coroutines.CoroutineContext,kotlin.coroutines.CoroutineContext)( diffCallback: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil.ItemCallback<T>, mainDispatcher: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html, workerDispatcher: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.coroutines/-coroutine-context/index.html )` | android |

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#addLoadStateListener(kotlin.Function1)(listener: (https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Add a `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates` listener to observe the loading state of the current `https://developer.android.com/reference/kotlin/androidx/paging/PagingData`. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#addOnPagesUpdatedListener(kotlin.Function0)(listener: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Add a listener which triggers after the pages presented to the UI are updated, even if the actual items presented don't change. | android |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#getItemCount()()` Returns the total number of items in the data set held by the adapter. | android |
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#getItemId(kotlin.Int)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Note: `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#getItemId(kotlin.Int)` is final, because stable IDs are unnecessary and therefore unsupported. | android |
| `T?` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#peek(kotlin.Int)(index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#refresh()()` Refresh the data presented by this `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#removeLoadStateListener(kotlin.Function1)(listener: (https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Remove a previously registered `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates` listener. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#removeOnPagesUpdatedListener(kotlin.Function0)(listener: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Remove a previously registered listener for new `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` generations completing initial load and presenting to the UI. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#retry()()` Retry any failed load requests that would result in a `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error` update to this `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`. | android |
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#setHasStableIds(kotlin.Boolean)(hasStableIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Stable ids are unsupported by `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`. | android |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy)( strategy: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy )` Sets the state restoration strategy for the Adapter. | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/ItemSnapshotList<T>` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#snapshot()()` Returns a new `https://developer.android.com/reference/kotlin/androidx/paging/ItemSnapshotList` representing the currently presented items, including any placeholders if they are enabled. | android |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.paging.PagingData)(pagingData: https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>)` Present a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` until it is invalidated by a call to `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#refresh()` or `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalidate()`. | android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.lifecycle.Lifecycle,androidx.paging.PagingData)(lifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle, pagingData: https://developer.android.com/reference/kotlin/androidx/paging/PagingData<T>)` Present a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` until it is either invalidated or another call to `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.lifecycle.Lifecycle,androidx.paging.PagingData)` is made. | android |
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateFooter(androidx.paging.LoadStateAdapter)(footer: https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter<*>)` Create a `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` with the provided `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter`s displaying the `https://developer.android.com/reference/kotlin/androidx/paging/LoadState` as a list item at the start of the presented list. | android |
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateHeader(androidx.paging.LoadStateAdapter)(header: https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter<*>)` Create a `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` with the provided `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter`s displaying the `https://developer.android.com/reference/kotlin/androidx/paging/LoadState` as a list item at the end of the presented list. | android |
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateHeaderAndFooter(androidx.paging.LoadStateAdapter,androidx.paging.LoadStateAdapter)( header: https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter<*>, footer: https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter<*> )` Create a `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` with the provided `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter`s displaying the `https://developer.android.com/reference/kotlin/androidx/paging/LoadType#PREPEND` and `https://developer.android.com/reference/kotlin/androidx/paging/LoadState`s as list items at the start and end respectively. | android |

| ### Protected functions |
|---|---|---|
| `T?` | `@https://developer.android.com/reference/kotlin/androidx/annotation/MainThread https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#getItem(kotlin.Int)(position: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns the presented item at the specified position, notifying Paging of the item access to trigger any loads necessary to fulfill `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#prefetchDistance()`. | android |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#itemCount()` | android |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates>` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#loadStateFlow()` A hot `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates` that emits a snapshot whenever the loading state of the current `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` changes. | android |
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html>` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#onPagesUpdatedFlow()` A hot `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` that emits after the pages presented to the UI are updated, even if the actual items presented don't change. | android |

### Inherited functions

From [androidx.recyclerview.widget.RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#bindViewHolder(VH,int)(holder: VH, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` android `VH` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#createViewHolder(android.view.ViewGroup,int)(parent: https://developer.android.com/reference/android/view/ViewGroup.html, viewType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `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: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter<https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder>,
viewHolder: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder,
localPosition: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html
)`

Returns the position of the given `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder` in the given `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter`.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemViewType(int)(position: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#hasObservers()()`

Returns true if one or more observers are attached to this adapter.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyDataSetChanged()()`

Notify any registered observers that the data set has changed.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Notify any registered observers that the item at `position` has changed.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemChanged(int,java.lang.Object)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, payload: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemInserted(int)(position: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemMoved(int,int)(fromPosition: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, toPosition: 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`.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int)(positionStart: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, itemCount: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeChanged(int,int,java.lang.Object)(positionStart: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, itemCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, payload: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeInserted(int,int)(positionStart: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, itemCount: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRangeRemoved(int,int)(positionStart: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, itemCount: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyItemRemoved(int)(position: 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.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onAttachedToRecyclerView(androidx.recyclerview.widget.RecyclerView)(recyclerView: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`

Called by RecyclerView when it starts observing this Adapter.
android `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int)(holder: VH, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int,java.util.List<java.lang.Object>)(holder: VH, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, payloads: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html>)` android `abstract VH` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onCreateViewHolder(android.view.ViewGroup,int)(parent: https://developer.android.com/reference/android/view/ViewGroup.html, viewType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onDetachedFromRecyclerView(androidx.recyclerview.widget.RecyclerView)(recyclerView: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)`

Called by RecyclerView when it stops observing this Adapter.
android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onFailedToRecycleView(VH)(holder: VH)` android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onViewAttachedToWindow(VH)(holder: VH)` android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onViewDetachedFromWindow(VH)(holder: VH)` android `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onViewRecycled(VH)(holder: VH)` android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#registerAdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver)(observer: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.AdapterDataObserver)`

Register a new observer to listen for data changes.
android `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#unregisterAdapterDataObserver(androidx.recyclerview.widget.RecyclerView.AdapterDataObserver)(
observer: https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.AdapterDataObserver
)`

Unregister an observer currently listening for data changes.
android

### Inherited properties

From [androidx.recyclerview.widget.RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter) `final https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#stateRestorationPolicy()` android

## Public constructors

### PagingDataAdapter

android

```
<T : Any, VH : RecyclerView.ViewHolder> PagingDataAdapter(
    diffCallback: DiffUtil.ItemCallback<T>,
    mainDispatcher: CoroutineContext = Dispatchers.Main,
    workerDispatcher: CoroutineContext = Dispatchers.Default
)
```

## Public functions

### addLoadStateListener

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

```
fun addLoadStateListener(listener: (CombinedLoadStates) -> Unit): Unit
```

Add a `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates` listener to observe the loading state of the current `https://developer.android.com/reference/kotlin/androidx/paging/PagingData`.

As new `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` generations are submitted and displayed, the listener will be notified to reflect the current `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates`.

```kotlin
import androidx.paging.LoadState

val adapter = UserPagingAdapter()
adapter.addLoadStateListener {
    // show a retry button outside the list when refresh hits an error
    retryButton.isVisible = it.refresh is LoadState.Error

    // swipeRefreshLayout displays whether refresh is occurring
    swipeRefreshLayout.isRefreshing = it.refresh is LoadState.Loading

    // show an empty state over the list when loading initially, before items are loaded
    emptyState.isVisible = it.refresh is LoadState.Loading && adapter.itemCount == 0
}
```

| Parameters |
|---|---|
| `listener: (https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStates` listener to receive updates. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#removeLoadStateListener(kotlin.Function1)` |   |

### addOnPagesUpdatedListener

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

```
fun addOnPagesUpdatedListener(listener: () -> Unit): Unit
```

Add a listener which triggers after the pages presented to the UI are updated, even if the actual items presented don't change.

An update is triggered from one of the following:

- `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.paging.PagingData)` is called and initial load completes, regardless of any differences in the loaded data

- A `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` is inserted

- A `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` is dropped

| Parameters |
|---|---|
| `listener: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | called after pages presented are updated. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#removeOnPagesUpdatedListener(kotlin.Function0)` |   |

### getItemCount

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

```
open fun getItemCount(): Int
```

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

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

### getItemId

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

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

Note: `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#getItemId(kotlin.Int)` is final, because stable IDs are unnecessary and therefore unsupported.

`https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`'s async diffing means that efficient change animations are handled for you, without the performance drawbacks of `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#notifyDataSetChanged()`. Instead, the diffCallback parameter of the `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter` serves the same functionality - informing the adapter and `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView` how items are changed and moved.

### peek

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

```
@MainThread
fun peek(index: @IntRange(from = 0) Int): T?
```

Returns the presented item at the specified position, without notifying Paging of the item access that would normally trigger page loads.

| Parameters |
|---|---|
| `index: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Index of the presented item to return, including placeholders. |

| Returns |
|---|---|
| `T?` | The presented item at position `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#peek(kotlin.Int)`, `null` if it is a placeholder. |

### refresh

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

```
fun refresh(): Unit
```

Refresh the data presented by this `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`.

`https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#refresh()` triggers the creation of a new `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` with a new instance of `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource` to represent an updated snapshot of the backing dataset. If a `https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator` is set, calling `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#refresh()` will also trigger a call to `https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator#load(androidx.paging.LoadType,androidx.paging.PagingState)` with `https://developer.android.com/reference/kotlin/androidx/paging/LoadType#REFRESH` to allow `https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator` to check for updates to the dataset backing `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`.

Note: This API is intended for UI-driven refresh signals, such as swipe-to-refresh. Invalidation due repository-layer signals, such as DB-updates, should instead use `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalidate()`.

```kotlin
import androidx.appcompat.app.AppCompatActivity
import androidx.paging.LoadState

class MyActivity : AppCompatActivity() {
    private lateinit var binding: MyActivityBinding
    private val pagingAdapter = UserPagingAdapter()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = MyActivityBinding.inflate(layoutInflater)
        setContentView(binding.root)

        binding.recyclerView.adapter = pagingAdapter
        pagingAdapter.addLoadStateListener { loadStates ->
            binding.swipeRefreshLayout.isRefreshing = loadStates.refresh is LoadState.Loading
        }

        binding.swipeRefreshLayout.setOnRefreshListener { pagingAdapter.refresh() }
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalidate()` |   |

### removeLoadStateListener

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

```
fun removeLoadStateListener(listener: (CombinedLoadStates) -> Unit): Unit
```

Remove a previously registered `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates` listener.

| Parameters |
|---|---|
| `listener: (https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Previously registered listener. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#addLoadStateListener(kotlin.Function1)` |   |

### removeOnPagesUpdatedListener

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

```
fun removeOnPagesUpdatedListener(listener: () -> Unit): Unit
```

Remove a previously registered listener for new `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` generations completing initial load and presenting to the UI.

| Parameters |
|---|---|
| `listener: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | Previously registered listener. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#addOnPagesUpdatedListener(kotlin.Function0)` |   |

### retry

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

```
fun retry(): Unit
```

Retry any failed load requests that would result in a `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error` update to this `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`.

Unlike `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#refresh()`, this does not invalidate `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource`, it only retries failed loads within the same generation of `https://developer.android.com/reference/kotlin/androidx/paging/PagingData`.

`https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error` can be generated from two types of load requests:

- `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#load(androidx.paging.PagingSource.LoadParams)` returning `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Error`

- `https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator#load(androidx.paging.LoadType,androidx.paging.PagingState)` returning `https://developer.android.com/reference/kotlin/androidx/paging/RemoteMediator.MediatorResult.Error`

### setHasStableIds

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

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

Stable ids are unsupported by `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`. Calling this method is an error and will result in an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html`.

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

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unsupported-operation-exception/index.html` | Always thrown, since this is unsupported by `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`. |

### setStateRestorationPolicy

android

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

Sets the state restoration strategy for the Adapter. By default, it is set to `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 `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#PREVENT_WHEN_EMPTY` or `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 `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#setStateRestorationPolicy(androidx.recyclerview.widget.RecyclerView.Adapter.StateRestorationPolicy)` with either `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter.StateRestorationPolicy#ALLOW` or `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 `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 `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 `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getStateRestorationPolicy()`.

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

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

### snapshot

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

```
fun snapshot(): ItemSnapshotList<T>
```

Returns a new `https://developer.android.com/reference/kotlin/androidx/paging/ItemSnapshotList` representing the currently presented items, including any placeholders if they are enabled.

### submitData

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

```
suspend fun submitData(pagingData: PagingData<T>): Unit
```

Present a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` until it is invalidated by a call to `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#refresh()` or `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#invalidate()`.

This method is typically used when collecting from a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` produced by `https://developer.android.com/reference/kotlin/androidx/paging/Pager`. For RxJava or LiveData support, use the non-suspending overload of `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.paging.PagingData)`, which accepts a `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`.

Note: This method suspends while it is actively presenting page loads from a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData`, until the `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` is invalidated. Although cancellation will propagate to this call automatically, collecting from a `https://developer.android.com/reference/kotlin/androidx/paging/Pager#flow()` with the intention of presenting the most up-to-date representation of your backing dataset should typically be done using `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html`.

```kotlin
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope

class MyFlowActivity : AppCompatActivity() {
    val pagingAdapter = UserPagingAdapter()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val viewModel by viewModels<UserListViewModel>()

        lifecycleScope.launch {
            viewModel.pagingFlow.collectLatest { pagingData ->
                // submitData suspends until loading this generation of data stops
                // so be sure to use collectLatest {} when presenting a Flow<PagingData>
                pagingAdapter.submitData(pagingData)
            }
        }
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/Pager` |   |

### submitData

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

```
fun submitData(lifecycle: Lifecycle, pagingData: PagingData<T>): Unit
```

Present a `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` until it is either invalidated or another call to `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.lifecycle.Lifecycle,androidx.paging.PagingData)` is made.

This method is typically used when observing a RxJava or LiveData stream produced by `https://developer.android.com/reference/kotlin/androidx/paging/Pager`. For `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` support, use the suspending overload of `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.lifecycle.Lifecycle,androidx.paging.PagingData)`, which automates cancellation via `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-coroutine-scope/index.html` instead of relying of `https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle`.

```kotlin
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity

class MyLiveDataActivity : AppCompatActivity() {
    val pagingAdapter = UserPagingAdapter()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val viewModel by viewModels<UserListViewModel>()

        viewModel.pagingLiveData.observe(this) { pagingData ->
            pagingAdapter.submitData(lifecycle, pagingData)
        }
    }
}
```

```kotlin
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity

class MyRxJava2Activity : AppCompatActivity() {
    val pagingAdapter = UserPagingAdapter()
    val disposable = CompositeDisposable()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val viewModel by viewModels<UserListViewModel>()

        viewModel.pagingFlowable
            .autoDispose(this) // Using AutoDispose to handle subscription lifecycle
            .subscribe { pagingData -> pagingAdapter.submitData(lifecycle, pagingData) }
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.lifecycle.Lifecycle,androidx.paging.PagingData)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/Pager` |   |

### withLoadStateFooter

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

```
fun withLoadStateFooter(footer: LoadStateAdapter<*>): ConcatAdapter
```

Create a `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` with the provided `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter`s displaying the `https://developer.android.com/reference/kotlin/androidx/paging/LoadState` as a list item at the start of the presented list.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateHeaderAndFooter(androidx.paging.LoadStateAdapter,androidx.paging.LoadStateAdapter)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateHeader(androidx.paging.LoadStateAdapter)` |   |

### withLoadStateHeader

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

```
fun withLoadStateHeader(header: LoadStateAdapter<*>): ConcatAdapter
```

Create a `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` with the provided `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter`s displaying the `https://developer.android.com/reference/kotlin/androidx/paging/LoadState` as a list item at the end of the presented list.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateHeaderAndFooter(androidx.paging.LoadStateAdapter,androidx.paging.LoadStateAdapter)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateFooter(androidx.paging.LoadStateAdapter)` |   |

### withLoadStateHeaderAndFooter

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

```
fun withLoadStateHeaderAndFooter(
    header: LoadStateAdapter<*>,
    footer: LoadStateAdapter<*>
): ConcatAdapter
```

Create a `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` with the provided `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter`s displaying the `https://developer.android.com/reference/kotlin/androidx/paging/LoadType#PREPEND` and `https://developer.android.com/reference/kotlin/androidx/paging/LoadState`s as list items at the start and end respectively.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateHeader(androidx.paging.LoadStateAdapter)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateFooter(androidx.paging.LoadStateAdapter)` |   |

## Protected functions

### getItem

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

```
@MainThread
protected fun getItem(position: @IntRange(from = 0) Int): T?
```

Returns the presented item at the specified position, notifying Paging of the item access to trigger any loads necessary to fulfill `https://developer.android.com/reference/kotlin/androidx/paging/PagingConfig#prefetchDistance()`.

| Parameters |
|---|---|
| `position: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Index of the presented item to return, including placeholders. |

| Returns |
|---|---|
| `T?` | The presented item at `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#getItem(kotlin.Int)`, `null` if it is a placeholder |

## Public properties

### itemCount

android Added in 3.0.0

```
open val itemCount: Int
```

### loadStateFlow

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

```
val loadStateFlow: Flow<CombinedLoadStates>
```

A hot `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` of `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates` that emits a snapshot whenever the loading state of the current `https://developer.android.com/reference/kotlin/androidx/paging/PagingData` changes.

This flow is conflated, so it buffers the last update to `https://developer.android.com/reference/kotlin/androidx/paging/CombinedLoadStates` and immediately delivers the current load states on collection.

### onPagesUpdatedFlow

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

```
val onPagesUpdatedFlow: Flow<Unit>
```

A hot `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` that emits after the pages presented to the UI are updated, even if the actual items presented don't change.

An update is triggered from one of the following:

- `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#submitData(androidx.paging.PagingData)` is called and initial load completes, regardless of any differences in the loaded data

- A `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` is inserted

- A `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` is dropped

Note: This is a `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-shared-flow/index.html` configured to replay 0 items with a buffer of size 64. If a collector lags behind page updates, it may trigger multiple times for each intermediate update that was presented while your collector was still working. To avoid this behavior, you can `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/index.html` this `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/index.html` so that you only receive the latest update, which is useful in cases where you are simply updating UI and don't care about tracking the exact number of page updates.