# SelectionTracker.SelectionPredicate

# 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)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate "View this page in Java")

<br />

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

<br />

*** ** * ** ***

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

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

## Summary

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

|                                      ### Public functions                                      |
|------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [canSelectMultiple](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSelectMultiple())`()` Permits restriction to single selection mode.                                                                                                                                                                                                                        |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [canSetStateAtPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSetStateAtPosition(int,boolean))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, nextState: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Validates a change to selection for a specific position. |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [canSetStateForKey](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/SelectionTracker.SelectionPredicate#canSetStateForKey(K,boolean))`(key: K, nextState: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Validates a change to selection for a specific key.                                                                                                 |

## Public constructors

### SelectionPredicate

Added in 1.0.0  

```
SelectionPredicate()
```  

## Public functions

### canSelectMultiple

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

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

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | 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)  

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

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

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|----------------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)          | the item position                            |
| `nextState: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | the next potential selected/unselected state |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | 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)  

```
abstract fun canSetStateForKey(key: K, nextState: Boolean): Boolean
```

Validates a change to selection for a specific key.  

|                                            Parameters                                            |
|--------------------------------------------------------------------------------------------------|----------------------------------------------|
| `key: K`                                                                                         | the item key                                 |
| `nextState: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | the next potential selected/unselected state |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if the item at`id`can be set to`nextState`. |