StableIdKeyProvider
class StableIdKeyProvider : ItemKeyProvider<Long!>
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 |
From class ItemKeyProvider
Int |
SCOPE_CACHED
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.
|
Int |
SCOPE_MAPPED
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.
|
|
Public constructors |
Creates a new key provider that uses cached long stable ids associated with the RecyclerView items.
|
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