ScrollStateHolder

class ScrollStateHolder(savedInstanceState: Bundle? = null)

Persists scroll state for nested RecyclerViews.

  1. Call saveScrollState in RecyclerView.Adapter.onViewRecycled to save the scroll position.

  2. Call restoreScrollState in RecyclerView.Adapter.onBindViewHolder after changing the adapter's contents to restore the scroll position

In fragment or activity override fun onSaveInstanceState(outState: Bundle) { super.onSaveInstanceState(outState) if (::scrollStateHolder.isInitialized) scrollStateHolder.onSaveInstanceState(outState) }

private lateinit var scrollStateHolder: ScrollStateHolder override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) scrollStateHolder = ScrollStateHolder(savedInstanceState) }

Constructors

Link copied to clipboard
constructor(savedInstanceState: Bundle? = null)

Types

Link copied to clipboard
object Companion
Link copied to clipboard

Provides a key that uniquely identifies a RecyclerView

Functions

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Restores this RecyclerView layout state for a given key

Link copied to clipboard

Saves this RecyclerView layout state for a given key

Link copied to clipboard