# LoadStateAdapter

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

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- android

  ```
  abstract class LoadStateAdapter<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.LoadStateAdapter](https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter) |

*** ** * ** ***

Adapter for displaying a RecyclerView item based on `https://developer.android.com/reference/kotlin/androidx/paging/LoadState`, such as a loading spinner, or a retry error button.

By default will use one shared `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemViewType(int)` for all items.

By default, both `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Loading` and `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error` are presented as adapter items, other states are not. To configure this, override `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#displayLoadStateAsItem(androidx.paging.LoadState)`.

To present this Adapter as a header and or footer alongside your `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter`, see `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateHeaderAndFooter(androidx.paging.LoadStateAdapter,androidx.paging.LoadStateAdapter)`, or use `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ConcatAdapter` directly to concatenate Adapters.

```kotlin
import androidx.paging.LoadState
import androidx.paging.LoadStateAdapter
import androidx.recyclerview.widget.RecyclerView

class LoadStateViewHolder(parent: ViewGroup, retry: () -> Unit) :
    RecyclerView.ViewHolder(
        LayoutInflater.from(parent.context).inflate(R.layout.load_state_item, parent, false)
    ) {
    private val progressBar: ProgressBar = itemView.findViewById(R.id.progress_bar)
    private val errorMsg: TextView = itemView.findViewById(R.id.error_msg)
    private val retry: Button =
        itemView.findViewById<Button>(R.id.retry_button).also {
            it.setOnClickListener { retry.invoke() }
        }

    fun bind(loadState: LoadState) {
        if (loadState is LoadState.Error) {
            errorMsg.text = loadState.error.localizedMessage
        }
        progressBar.visibility = toVisibility(loadState is LoadState.Loading)
        retry.visibility = toVisibility(loadState !is LoadState.Loading)
        errorMsg.visibility = toVisibility(loadState !is LoadState.Loading)
    }

    private fun toVisibility(constraint: Boolean): Int =
        if (constraint) {
            View.VISIBLE
        } else {
            View.GONE
        }
}

/**
 * Adapter which displays a loading spinner when `state = LoadState.Loading`, and an error
 * message and retry button when `state is LoadState.Error`.
 */
class MyLoadStateAdapter(private val retry: () -> Unit) :
    LoadStateAdapter<LoadStateViewHolder>() {

    override fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState) =
        LoadStateViewHolder(parent, retry)

    override fun onBindViewHolder(holder: LoadStateViewHolder, loadState: LoadState) =
        holder.bind(loadState)
}
```

| See also |
|---|---|
| `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)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter#withLoadStateFooter(androidx.paging.LoadStateAdapter)` |   |

## Summary

| ### Public constructors |
|---|---|
| `<VH : https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder> https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#LoadStateAdapter()()` | android |

| ### Public functions |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#displayLoadStateAsItem(androidx.paging.LoadState)(loadState: https://developer.android.com/reference/kotlin/androidx/paging/LoadState)` Returns true if the LoadState should be displayed as a list item when active. | android |
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#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/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#getItemViewType(kotlin.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 |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#getStateViewType(androidx.paging.LoadState)(loadState: https://developer.android.com/reference/kotlin/androidx/paging/LoadState)` Override this method to use different view types per LoadState. | android |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#onBindViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder,androidx.paging.LoadState)(holder: VH, loadState: https://developer.android.com/reference/kotlin/androidx/paging/LoadState)` Called to bind the passed LoadState to the ViewHolder. | android |
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#onBindViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder,kotlin.Int)(holder: VH, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Called by RecyclerView to display the data at the specified position. | android |
| `abstract VH` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#onCreateViewHolder(android.view.ViewGroup,androidx.paging.LoadState)(parent: https://developer.android.com/reference/android/view/ViewGroup.html, loadState: https://developer.android.com/reference/kotlin/androidx/paging/LoadState)` Called to create a ViewHolder for the given LoadState. | android |
| `final VH` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#onCreateViewHolder(android.view.ViewGroup,kotlin.Int)(parent: https://developer.android.com/reference/android/view/ViewGroup.html, viewType: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Called when RecyclerView needs a new `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder` of the given type to represent an item. | android |

| ### Public properties |
|---|---|---|
| `final https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#itemCount()` | android |
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadState` | `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#loadState()` LoadState to present in the adapter. | 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/-long/index.html` `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemId(int)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`

Return the stable ID for the item at `position`.
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 `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 `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#setHasStableIds(boolean)(hasStableIds: 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 `https://developer.android.com/reference/java/lang/Long.html`.
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

### LoadStateAdapter

android

```
<VH : RecyclerView.ViewHolder> LoadStateAdapter()
```

## Public functions

### displayLoadStateAsItem

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

```
open fun displayLoadStateAsItem(loadState: LoadState): Boolean
```

Returns true if the LoadState should be displayed as a list item when active.

By default, `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Loading` and `https://developer.android.com/reference/kotlin/androidx/paging/LoadState.Error` present as list items, others do not.

### getItemCount

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

```
final 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. |

### getItemViewType

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

```
final 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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | position to query |

| Returns |
|---|---|
| `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. |

### getStateViewType

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

```
open fun getStateViewType(loadState: LoadState): Int
```

Override this method to use different view types per LoadState.

By default, this LoadStateAdapter only uses a single view type.

### onBindViewHolder

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

```
abstract fun onBindViewHolder(holder: VH, loadState: LoadState): Unit
```

Called to bind the passed LoadState to the ViewHolder.

| Parameters |
|---|---|
| `holder: VH` | the ViewHolder to bind to |
| `loadState: https://developer.android.com/reference/kotlin/androidx/paging/LoadState` | LoadState to display. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#getItemViewType(kotlin.Int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#displayLoadStateAsItem(androidx.paging.LoadState)` |   |

### onBindViewHolder

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

```
final 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 `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#itemView()` to reflect the item at the given position.

Note that unlike `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 `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapterPosition()` which will have the updated adapter position. Override `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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The position of the item within the adapter's data set. |

### onCreateViewHolder

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

```
abstract fun onCreateViewHolder(parent: ViewGroup, loadState: LoadState): VH
```

Called to create a ViewHolder for the given LoadState.

| Parameters |
|---|---|
| `parent: 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. |
| `loadState: https://developer.android.com/reference/kotlin/androidx/paging/LoadState` | The LoadState to be initially presented by the new ViewHolder. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#getItemViewType(kotlin.Int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/paging/LoadStateAdapter#displayLoadStateAsItem(androidx.paging.LoadState)` |   |

### onCreateViewHolder

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

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

Called when RecyclerView needs a new `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 `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 `https://developer.android.com/reference/android/view/View.html#findViewById(int)` calls.

| Parameters |
|---|---|
| `parent: 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: 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 |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#getItemViewType(int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter#onBindViewHolder(VH,int)` |   |

## Public properties

### itemCount

android Added in 3.0.0

```
final val itemCount: Int
```

### loadState

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

```
var loadState: LoadState
```

LoadState to present in the adapter.

Changing this property will immediately notify the Adapter to change the item it's presenting.