# ItemKeyProvider

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/ItemKeyProvider.java+class:androidx.recyclerview.selection.ItemKeyProvider) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/recyclerview#1.0.0)

*** ** * ** ***


```
public abstract class ItemKeyProvider<K>
```

<br />

Known direct subclasses [StableIdKeyProvider](https://developer.android.com/reference/androidx/recyclerview/selection/StableIdKeyProvider)

|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/selection/StableIdKeyProvider` | An `https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider` that provides stable ids by way of cached `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter` stable ids. |

*** ** * ** ***

Provides selection library access to stable selection keys identifying items presented by a `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView` instance.

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

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/androidx/annotation/IntDef(value = ) @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) public annotation https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider.Scope` |

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider#SCOPE_CACHED() = 1` Provides access to cached data based for items that were recently bound in the view. |
| `static final int` | `https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider#SCOPE_MAPPED() = 0` Provides access to all data, regardless of whether it is bound to a view or not. |

| ### Protected constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider#ItemKeyProvider(int)(@https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider.Scope int scope)` Creates a new provider with the given scope. |

| ### Public methods |
|---|---|
| `abstract @https://developer.android.com/reference/androidx/annotation/Nullable K` | `https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider#getKey(int)(int position)` |
| `abstract int` | `https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider#getPosition(K)(@https://developer.android.com/reference/androidx/annotation/NonNull K key)` |

## Constants

### SCOPE_CACHED

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

```
public static final int SCOPE_CACHED = 1
```

Provides access to cached data based for items that were recently bound in the view. Employing this provider will result in a reduced feature-set, as some features like SHIFT+click range selection and band selection are dependent on mapped access.

### SCOPE_MAPPED

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

```
public static final int SCOPE_MAPPED = 0
```

Provides access to all data, regardless of whether it is bound to a view or not. Key providers with this access type enjoy support for enhanced features like: SHIFT+click range selection, and band selection.

## Protected constructors

### ItemKeyProvider

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

```
protected ItemKeyProvider(@ItemKeyProvider.Scope int scope)
```

Creates a new provider with the given scope.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/recyclerview/selection/ItemKeyProvider.Scope int scope` | Scope can't be changed at runtime. |

## Public methods

### getKey

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

```
public abstract @Nullable K getKey(int position)
```

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable K` | The selection key at the given adapter position, or null. |

### getPosition

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

```
public abstract int getPosition(@NonNull K key)
```

| Returns |
|---|---|
| `int` | the position corresponding to the selection key, or RecyclerView.NO_POSITION. |