I want to limit my RecyclerView SelectionTracker selection size to 10 items (max).
SelectionTracker init code:
val selectionTracker = SelectionTracker.Builder(
"my_selection_tracker_id",
myRecyclerView,
MyItemKeyProvider(),
MyItemLookup(myRecyclerView),
StorageStrategy.createParcelableStorage(MyItemModel::class.java)
).withSelectionPredicate(SelectionPredicates.createSelectAnything())
.build()
Answer
After reading
SelectionTrackerdocumentation again, I found this one:So, I
override canSetStateForKey()method fromSelectionPredicateand add if condition which check item nextState (selected/deselected) and selected items size.
From documentation about canSetStateForKey():
Condition which limit selection size to 10:
Full SelectionTracker initialization: