# PreferenceGroup.PreferencePositionCallback

# PreferenceGroup.PreferencePositionCallback

Artifact:[androidx.preference:preference](https://developer.android.com/jetpack/androidx/releases/preference)  
[View Source](https://cs.android.com/search?q=file:androidx/preference/PreferenceGroup.java+class:androidx.preference.PreferenceGroup.PreferencePositionCallback)  
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/PreferenceGroup.PreferencePositionCallback "View this page in Java")

<br />

```
interface PreferenceGroup.PreferencePositionCallback
```

<br />

*** ** * ** ***

Interface for PreferenceGroup adapters to implement so that[scrollToPreference](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat#scrollToPreference(java.lang.String))and[scrollToPreference](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceFragmentCompat#scrollToPreference(androidx.preference.Preference))can determine the correct scroll position to request.

## Summary

|                            ### Public functions                             |
|-----------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getPreferenceAdapterPosition](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.PreferencePositionCallback#getPreferenceAdapterPosition(java.lang.String))`(key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)`)` Returns the adapter position of the first[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)with the specified key.                   |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [getPreferenceAdapterPosition](https://developer.android.com/reference/kotlin/androidx/preference/PreferenceGroup.PreferencePositionCallback#getPreferenceAdapterPosition(androidx.preference.Preference))`(preference: `[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)`)` Returns the adapter position of the specified[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)object |

## Public functions

### getPreferenceAdapterPosition

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

```
fun getPreferenceAdapterPosition(key: String): Int
```

Returns the adapter position of the first[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)with the specified key.  

|                                        Parameters                                        |
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
| `key: `[String](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html) | Key of[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)to find |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Adapter position of the[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)or[NO_POSITION](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_POSITION())if not found |

### getPreferenceAdapterPosition

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

```
fun getPreferenceAdapterPosition(preference: Preference): Int
```

Returns the adapter position of the specified[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)object  

|                                                Parameters                                                 |
|-----------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------|
| `preference: `[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference) | [Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)object to find |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Adapter position of the[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)or[NO_POSITION](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/RecyclerView#NO_POSITION())if not found |