SelectionPredicate

abstract class SelectionPredicate<K : Any!>
kotlin.Any
   ↳ androidx.recyclerview.selection.SelectionTracker.SelectionPredicate

Implement SelectionPredicate to control when items can be selected or unselected. See Builder#withSelectionPredicate(SelectionPredicate).

Summary

Public constructors

Implement SelectionPredicate to control when items can be selected or unselected.

Public methods
abstract Boolean

Permits restriction to single selection mode.

abstract Boolean
canSetStateForKey(@NonNull key: K, nextState: Boolean)

Validates a change to selection for a specific key.

abstract Boolean
canSetStateAtPosition(position: Int, nextState: Boolean)

Validates a change to selection for a specific position.

Public constructors

<init>

SelectionPredicate()

Implement SelectionPredicate to control when items can be selected or unselected. See Builder#withSelectionPredicate(SelectionPredicate).

Public methods

canSelectMultiple

abstract fun canSelectMultiple(): Boolean

Permits restriction to single selection mode. Single selection mode has unique behaviors in that it'll deselect an item already selected in order to select the new item.

In order to limit the number of items that can be selected, use canSetStateForKey(Object, boolean) and canSetStateAtPosition(int, boolean).

Return
Boolean: true if more than a single item can be selected.

canSetStateForKey

abstract fun canSetStateForKey(@NonNull key: K, nextState: Boolean): Boolean

Validates a change to selection for a specific key.

Parameters
key K: the item key
nextState K: the next potential selected/unselected state
Return
Boolean: true if the item at id can be set to nextState.

canSetStateAtPosition

abstract fun canSetStateAtPosition(position: Int, nextState: Boolean): Boolean

Validates a change to selection for a specific position. If necessary use ItemKeyProvider to identy associated key.

Parameters
position Int: the item position
nextState Int: the next potential selected/unselected state
Return
Boolean: true if the item at id can be set to nextState.