# PreferenceViewHolder

# PreferenceViewHolder

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/preference/PreferenceViewHolder "View this page in Java")

<br />

```
class PreferenceViewHolder : RecyclerView.ViewHolder
```

<br />

|---|---|-------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                                                        |||
| ↳ | [androidx.recyclerview.widget.RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder) ||
|   | ↳ | [androidx.preference.PreferenceViewHolder](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder) |

*** ** * ** ***

A[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)class which caches views associated with the default[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)layouts. Cached views can be retrieved by calling[findViewById](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder#findViewById(int)).

## Summary

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [View](https://developer.android.com/reference/android/view/View.html)`!`           | [findViewById](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder#findViewById(int))`(id: @`[IdRes](https://developer.android.com/reference/kotlin/androidx/annotation/IdRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns a cached reference to a subview managed by this object.                  |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isDividerAllowedAbove](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder#isDividerAllowedAbove())`()` Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it.                                                                                                        |
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [isDividerAllowedBelow](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder#isDividerAllowedBelow())`()` Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it.                                                                                                        |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setDividerAllowedAbove](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder#setDividerAllowedAbove(boolean))`(allowed: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)       | [setDividerAllowedBelow](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceViewHolder#setDividerAllowedBelow(boolean))`(allowed: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it. |

|                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              ### Inherited functions                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.recyclerview.widget.RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder) |----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                    | [getAbsoluteAdapterPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getAbsoluteAdapterPosition())`()` Returns the Adapter position of the item represented by this ViewHolder with respect to the[RecyclerView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView)'s[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter). | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                    | ~~[getAdapterPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getAdapterPosition())~~`()` **This function is deprecated.** This method is confusing when adapters nest other adapters. <br />                                                                                                                                                                                                                           | | [RecyclerView.Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)`<`[RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder)`!>?` | [getBindingAdapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapter())`()` Returns the[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)that last bound this[ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder).                                                                        | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                    | [getBindingAdapterPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getBindingAdapterPosition())`()` Returns the Adapter position of the item represented by this ViewHolder with respect to the[Adapter](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.Adapter)that bound it.                                                                                                | | [Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)                                                                                                                                                                                  | [getItemId](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getItemId())`()` Returns The itemId represented by this ViewHolder.                                                                                                                                                                                                                                                                                                  | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                    | [getItemViewType](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getItemViewType())`()`                                                                                                                                                                                                                                                                                                                                         | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                    | [getLayoutPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getLayoutPosition())`()` Returns the position of the ViewHolder in terms of the latest layout pass.                                                                                                                                                                                                                                                          | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                    | [getOldPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getOldPosition())`()` When LayoutManager supports animations, RecyclerView tracks 3 positions for ViewHolders to perform animations.                                                                                                                                                                                                                            | | [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                                                                                                                                                                                    | ~~[getPosition](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#getPosition())~~`()` **This function is deprecated.** This method is deprecated because its meaning is ambiguous due to the async handling of adapter updates. <br />                                                                                                                                                                                            | | [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)                                                                                                                                                                            | [isRecyclable](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#isRecyclable())`()`                                                                                                                                                                                                                                                                                                                                               | | [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                  | [setIsRecyclable](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#setIsRecyclable(boolean))`(recyclable: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)`)` Informs the recycler whether this item can be recycled.                                                                                                                                                                         | | [String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`!`                                                                                                                                                                           | [toString](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#toString())`()`                                                                                                                                                                                                                                                                                                                                                       | |

|                                                                                                                                                                                                                                                                            ### Inherited properties                                                                                                                                                                                                                                                                             |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From[androidx.recyclerview.widget.RecyclerView.ViewHolder](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder) |------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------| | [View](https://developer.android.com/reference/android/view/View.html) | [itemView](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView.ViewHolder#itemView()) | |

## Public functions

### findViewById

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

```
fun findViewById(id: @IdRes Int): View!
```

Returns a cached reference to a subview managed by this object. If the view reference is not yet cached, it falls back to calling[findViewById](https://developer.android.com/reference/android/view/View.html#findViewById(int))and caches the result.  

|                                                                               Parameters                                                                               |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------|
| `id: @`[IdRes](https://developer.android.com/reference/kotlin/androidx/annotation/IdRes)` `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Resource ID of the view to find |

|                                  Returns                                  |
|---------------------------------------------------------------------------|-------------------------------------------------------------|
| [View](https://developer.android.com/reference/android/view/View.html)`!` | The view, or`null`if no view with the requested ID is found |

### isDividerAllowedAbove

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

```
fun isDividerAllowedAbove(): Boolean
```

Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-----------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if dividers are allowed above this item |

### isDividerAllowedBelow

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

```
fun isDividerAllowedBelow(): Boolean
```

Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it.  

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|-----------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`if dividers are allowed below this item |

### setDividerAllowedAbove

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

```
fun setDividerAllowedAbove(allowed: Boolean): Unit
```

Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it. By default,[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder))will set this to the same value as returned by[isSelectable](https://developer.android.com/reference/kotlin/androidx/preference/Preference#isSelectable()), so that non-selectable items do not have a divider drawn above them.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| `allowed: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | False to prevent dividers being drawn above this item |

### setDividerAllowedBelow

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

```
fun setDividerAllowedBelow(allowed: Boolean): Unit
```

Dividers are only drawn between items if both items allow it, or above the first and below the last item if that item allows it. By default,[onBindViewHolder](https://developer.android.com/reference/kotlin/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder))will set this to the same value as returned by[isSelectable](https://developer.android.com/reference/kotlin/androidx/preference/Preference#isSelectable()), so that non-selectable items do not have a divider drawn below them.  

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|-------------------------------------------------------|
| `allowed: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | False to prevent dividers being drawn below this item |