Skip to content

Most visited

Recently visited


belongs to Maven artifact


public final class StableIdKeyProvider
extends ItemKeyProvider<Long>

   ↳ androidx.recyclerview.selection.ItemKeyProvider<java.lang.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).


Inherited constants

From class androidx.recyclerview.selection.ItemKeyProvider

Public constructors

StableIdKeyProvider(RecyclerView recyclerView)

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

Public methods

Long getKey(int position)
int getPosition(Long key)

Inherited methods

From class androidx.recyclerview.selection.ItemKeyProvider
From class java.lang.Object

Public constructors


StableIdKeyProvider (RecyclerView recyclerView)

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

recyclerView RecyclerView: the owner RecyclerView

Public methods


Long getKey (int position)

position int

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


int getPosition (Long key)

key Long

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

This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields


Follow Google Developers on WeChat

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience. (Dec 2017 Android Platform & Tools Survey)