# SelectionTracker.SelectionPredicate

Artifact: [androidx.recyclerview:recyclerview-selection](https://developer.android.com/jetpack/androidx/releases/recyclerview) [View Source](https://cs.android.com/search?q=file:androidx/recyclerview/selection/SelectionTracker.java+class:androidx.recyclerview.selection.SelectionTracker.SelectionPredicate) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***


```
public abstract class SelectionTracker.SelectionPredicate<K>
```

<br />

*** ** * ** ***

Implement SelectionPredicate to control when items can be selected or unselected. See `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.Builder#withSelectionPredicate(androidx.recyclerview.selection.SelectionTracker.SelectionPredicate<K>)`.

| Parameters |
|---|---|
| `<K>` | Selection key type. @see `https://developer.android.com/reference/androidx/recyclerview/selection/StorageStrategy` for supported types. |

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#SelectionPredicate()()` |

| ### Public methods |
|---|---|
| `abstract boolean` | `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSelectMultiple()()` Permits restriction to single selection mode. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSetStateAtPosition(int,boolean)(int position, boolean nextState)` Validates a change to selection for a specific position. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSetStateForKey(K,boolean)(@https://developer.android.com/reference/androidx/annotation/NonNull K key, boolean nextState)` Validates a change to selection for a specific key. |

## Public constructors

### SelectionPredicate

Added in 1.0.0

```
public SelectionPredicate()
```

## Public methods

### canSelectMultiple

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public abstract boolean canSelectMultiple()
```

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 `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSetStateForKey(K,boolean)` and `https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSetStateAtPosition(int,boolean)`.

| Returns |
|---|---|
| `boolean` | true if more than a single item can be selected. |

### canSetStateAtPosition

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public abstract boolean canSetStateAtPosition(int position, boolean nextState)
```

Validates a change to selection for a specific position. If necessary use `https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider` to identy associated key.

| Parameters |
|---|---|
| `int position` | the item position |
| `boolean nextState` | the next potential selected/unselected state |

| Returns |
|---|---|
| `boolean` | true if the item at `id` can be set to `nextState`. |

### canSetStateForKey

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

```
public abstract boolean canSetStateForKey(@NonNull K key, boolean nextState)
```

Validates a change to selection for a specific key.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull K key` | the item key |
| `boolean nextState` | the next potential selected/unselected state |

| Returns |
|---|---|
| `boolean` | true if the item at `id` can be set to `nextState`. |