StableIdKeyProvider

class StableIdKeyProvider : ItemKeyProvider<Long!>
kotlin.Any
   ↳ androidx.recyclerview.selection.ItemKeyProvider<kotlin.Long>
   ↳ androidx.recyclerview.selection.StableIdKeyProvider

An ItemKeyProvider that provides stable ids by way of cached RecyclerView.Adapter stable ids. Items enter the cache as they are laid out by RecyclerView, and are removed from the cache as they are recycled.

There are trade-offs with this implementation as it necessarily auto-boxes long stable id values into Long values for use as selection keys. The core Selection API uses a parameterized key type to permit other keys (such as Strings or URIs).

Summary

Inherited constants

Public constructors

<init>(@NonNull recyclerView: RecyclerView)

Creates a new key provider that uses cached long stable ids associated with the RecyclerView items.

Public methods

Long?
getKey(position: Int)

Int
getPosition(@NonNull key: Long)

Public constructors

<init>

StableIdKeyProvider(@NonNull recyclerView: RecyclerView)

Creates a new key provider that uses cached long stable ids associated with the RecyclerView items.

Parameters
recyclerView RecyclerView: the owner RecyclerView

Public methods

getKey

@Nullable fun getKey(position: Int): Long?

getPosition

fun getPosition(@NonNull key: Long): Int