StableIdKeyProvider


public final class StableIdKeyProvider extends ItemKeyProvider


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

Public constructors

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

Public methods

@Nullable Long
getKey(int position)
int

Inherited Constants

From androidx.recyclerview.selection.ItemKeyProvider
static final int

Provides access to cached data based for items that were recently bound in the view.

static final int

Provides access to all data, regardless of whether it is bound to a view or not.

Public constructors

StableIdKeyProvider

Added in 1.0.0
public StableIdKeyProvider(@NonNull RecyclerView recyclerView)

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

Parameters
@NonNull RecyclerView recyclerView

the owner RecyclerView

Public methods

getKey

Added in 1.2.0-alpha02
public @Nullable Long getKey(int position)
Returns
@Nullable Long

The selection key at the given adapter position, or null.

getPosition

Added in 1.0.0
public int getPosition(@NonNull Long key)
Returns
int

the position corresponding to the selection key, or RecyclerView.NO_POSITION.