public final class MutableSelection
extends Selection<K>

   ↳ androidx.recyclerview.selection.Selection<K>
     ↳ androidx.recyclerview.selection.MutableSelection<K>

Subclass of Selection exposing public support for mutating the underlying selection data. This is useful for clients of SelectionTracker that wish to manipulate a copy of selection data obtained via SelectionTracker.copySelection(MutableSelection).

While the Selection class is not intrinsically immutable, it is not mutable by non-library code. Furthermore the value returned from SelectionTracker.getSelection() is a live view of the underlying selection, mutable by the library itself.

MutableSelection allows clients to obtain a mutable copy of the Selection state held by the selection library. This is useful in situations where a stable snapshot of the selection is required.


 MutableSelection snapshot = new MutableSelection();

 // Clear the user visible selection.
 // tracker.getSelection().isEmpty() will be true.
 // shapshot has a copy of the previous selection.

See also:


Public constructors


Public methods

boolean add(K key)

Adds a new item to the primary selection.

void clear()

Clears the primary selection.

void copyFrom(Selection<K> source)

Clones primary and provisional selection from supplied Selection.

boolean remove(K key)

Removes an item from the primary selection.

Inherited methods