# FocusDelegate

# FocusDelegate

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/FocusDelegate.java+class:androidx.recyclerview.selection.FocusDelegate)  
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/FocusDelegate "View this page in Java")

<br />

```
abstract class FocusDelegate<K>
```

<br />

*** ** * ** ***

Override methods in this class to provide application specific behaviors related to focusing item.  

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

## Summary

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

|                                      ### Public functions                                      |
|------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [clearFocus](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/FocusDelegate#clearFocus())`()` If the environment supports focus and something is focused, unfocus it.                                                                                                                                                                                            |
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [focusItem](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/FocusDelegate#focusItem(androidx.recyclerview.selection.ItemDetailsLookup.ItemDetails<K>))`(item: `[ItemDetailsLookup.ItemDetails](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/ItemDetailsLookup.ItemDetails)`<K!>)` If environment supports focus, focus`item`. |
| `abstract `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)         | [getFocusedPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/FocusDelegate#getFocusedPosition())`()` Returns the position of the currently focused item, or[NO_POSITION](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_POSITION())if nothing is focused.                                                  |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [hasFocusedItem](https://developer.android.com/reference/kotlin/androidx/recyclerview/selection/FocusDelegate#hasFocusedItem())`()`                                                                                                                                                                                                                                                            |

## Public constructors

### FocusDelegate

Added in 1.0.0  

```
FocusDelegate()
```  

## Public functions

### clearFocus

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

```
abstract fun clearFocus(): Unit
```

If the environment supports focus and something is focused, unfocus it.  

### focusItem

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

```
abstract fun focusItem(item: ItemDetailsLookup.ItemDetails<K!>): Unit
```

If environment supports focus, focus`item`.  

### getFocusedPosition

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

```
abstract fun getFocusedPosition(): Int
```

Returns the position of the currently focused item, or[NO_POSITION](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_POSITION())if nothing is focused.

You must implement this feature if you intend your app to work well with mouse and keyboard. Selection ranges are inferred from focused item when there is no explicit last-selected item.

You can manage and advance focus using keyboard arrows, reflecting this state visibly in the view item. Use can then press shift, then click another item with their mouse to select all items between the focused item and the clicked item.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | the position of the currently focused item, or`RecyclerView#NO_POSITION`if none. |

### hasFocusedItem

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

```
abstract fun hasFocusedItem(): Boolean
```  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | true if there is a focused item. |