Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

ItemKeyProvider

abstract class ItemKeyProvider<K : Any!>
kotlin.Any
   ↳ androidx.recyclerview.selection.ItemKeyProvider

Provides selection library access to stable selection keys identifying items presented by a RecyclerView instance.

Summary

Nested classes

Constants

static Int

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

static Int

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

Protected constructors

<init>(scope: Int)

Creates a new provider with the given scope.

Public methods

abstract K?
getKey(position: Int)

abstract Int
getPosition(@NonNull key: K)

Constants

SCOPE_CACHED

static val SCOPE_CACHED: Int

Provides access to cached data based for items that were recently bound in the view. Employing this provider will result in a reduced feature-set, as some features like SHIFT+click range selection and band selection are dependent on mapped access.

Value: 1

SCOPE_MAPPED

static val SCOPE_MAPPED: Int

Provides access to all data, regardless of whether it is bound to a view or not. Key providers with this access type enjoy support for enhanced features like: SHIFT+click range selection, and band selection.

Value: 0

Protected constructors

<init>

protected ItemKeyProvider(scope: Int)

Creates a new provider with the given scope.

Parameters
scope Int: Scope can't be changed at runtime.

Public methods

getKey

@Nullable abstract fun getKey(position: Int): K?
Return
K?: The selection key at the given adapter position, or null.

getPosition

abstract fun getPosition(@NonNull key: K): Int
Return
Int: the position corresponding to the selection key, or RecyclerView.NO_POSITION.