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

*** ** * ** ***


```
public class PreferenceViewHolder extends RecyclerView.ViewHolder
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.recyclerview.widget.RecyclerView.ViewHolder](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder) ||
|   | ↳ | [androidx.preference.PreferenceViewHolder](https://developer.android.com/reference/androidx/preference/PreferenceViewHolder) |

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/preference/PreferenceViewHolder#findViewById(int)(@https://developer.android.com/reference/androidx/annotation/IdRes int id)` Returns a cached reference to a subview managed by this object. |
| `boolean` | `https://developer.android.com/reference/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://developer.android.com/reference/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. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceViewHolder#setDividerAllowedAbove(boolean)(boolean allowed)` 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. |
| `void` | `https://developer.android.com/reference/androidx/preference/PreferenceViewHolder#setDividerAllowedBelow(boolean)(boolean allowed)` 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 fields |
|---|
| From [androidx.recyclerview.widget.RecyclerView.ViewHolder](https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder) |---|---| | `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html` | `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.ViewHolder#itemView()` | |

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

## Public methods

### findViewById

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

```
public View findViewById(@IdRes int id)
```

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

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/IdRes int id` | Resource ID of the view to find |

| Returns |
|---|---|
| `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)

```
public boolean 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.

| Returns |
|---|---|
| `boolean` | `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)

```
public boolean 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.

| Returns |
|---|---|
| `boolean` | `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)

```
public void setDividerAllowedAbove(boolean allowed)
```

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, `https://developer.android.com/reference/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder)` will set this to the same value as returned by `https://developer.android.com/reference/androidx/preference/Preference#isSelectable()`, so that non-selectable items do not have a divider drawn above them.

| Parameters |
|---|---|
| `boolean allowed` | 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)

```
public void setDividerAllowedBelow(boolean allowed)
```

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, `https://developer.android.com/reference/androidx/preference/Preference#onBindViewHolder(androidx.preference.PreferenceViewHolder)` will set this to the same value as returned by `https://developer.android.com/reference/androidx/preference/Preference#isSelectable()`, so that non-selectable items do not have a divider drawn below them.

| Parameters |
|---|---|
| `boolean allowed` | False to prevent dividers being drawn below this item |