The Android Developer Challenge is back! Submit your idea before December 2.

MutableSelection

class MutableSelection<K : Any!> : Selection<K>
kotlin.Any
   ↳ androidx.recyclerview.selection.Selection<K>
   ↳ androidx.recyclerview.selection.MutableSelection

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.
  

Summary

Public constructors

Subclass of Selection exposing public support for mutating the underlying selection data.

Public methods

Boolean
add(@NonNull key: K)

Unit

Unit
copyFrom(@NonNull source: Selection<K>)

Boolean
remove(@NonNull key: K)

Inherited functions

Public constructors

<init>

MutableSelection()

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.
  

Public methods

add

fun add(@NonNull key: K): Boolean

clear

fun clear(): Unit

copyFrom

fun copyFrom(@NonNull source: Selection<K>): Unit

remove

fun remove(@NonNull key: K): Boolean