MutableSelection

public final class MutableSelection
extends Selection<K>

java.lang.Object
   ↳ 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.

Example

 MutableSelection snapshot = new MutableSelection();
 selectionTracker.copySelection(snapshot);

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

See also:

Summary

Public constructors

MutableSelection()

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

Public constructors

MutableSelection

public MutableSelection ()

Public methods

add

public boolean add (K key)

Adds a new item to the primary selection.

Parameters
key K

Returns
boolean true if the operation resulted in a modification to the selection.

clear

public void clear ()

Clears the primary selection. The provisional selection, if any, is unaffected.

copyFrom

public void copyFrom (Selection<K> source)

Clones primary and provisional selection from supplied Selection. Does not copy active range data.

Parameters
source Selection

remove

public boolean remove (K key)

Removes an item from the primary selection.

Parameters
key K

Returns
boolean true if the operation resulted in a modification to the selection.