![]() Setting that option to true will just tell the RecyclerView that each item in the data set can be represented with a unique identifier of type Long which is exactly what we need. With that in mind, we are going to pick Long and use the position of our list items as their ids, but first, we need the ids to be stable so we will use setHasStableIds for that. Band selection support is not available when using the default long key storage implementation. It comes with some limitations, however, as access to stable ids at runtime is limited. Long: Use Long when RecyclerView's long stable ids are already in use. ![]() String: Use String when a string based stable identifier is available. If items in your view are associated with stable content:// uris, you should use Uri for your key type. This is especially useful in conjunction with Uri as the Android URI implementation is both parcelable and makes for a natural stable selection key for values represented by the Android Content Provider framework. Parcelable: Any Parcelable type can be used as the selection key. There are also some guidelines and advice on which type to use depending on your use case. You can use whichever type you like but the selection library provides support for three types: Parcelable, String and Long. The documentation first calls to determine the selection key type to use to then build a KeyProvider. ![]() implementation 'androidx.recyclerview:recyclerview-selection:1.0.0' Step 2: Select a key type The first step is adding the dependency to our gradle.build file.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |