# Preference.OnPreferenceChangeListener

# Preference.OnPreferenceChangeListener

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

<br />

```
interface Preference.OnPreferenceChangeListener
```

<br />

*** ** * ** ***

Interface definition for a callback to be invoked when the value of this[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)has been changed by the user and is about to be set and/or persisted. This gives the client a chance to prevent setting and/or persisting the value.

## Summary

|                                ### Public functions                                 |
|-------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [onPreferenceChange](https://developer.android.com/reference/kotlin/androidx/preference/Preference.OnPreferenceChangeListener#onPreferenceChange(androidx.preference.Preference,java.lang.Object))`(preference: `[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference)`, newValue: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!)` Called when a preference has been changed by the user. |

## Public functions

### onPreferenceChange

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

```
fun onPreferenceChange(preference: Preference, newValue: Any!): Boolean
```

Called when a preference has been changed by the user. This is called before the state of the preference is about to be updated and before the state is persisted.  

|                                                Parameters                                                 |
|-----------------------------------------------------------------------------------------------------------|---------------------------------|
| `preference: `[Preference](https://developer.android.com/reference/kotlin/androidx/preference/Preference) | The changed preference          |
| `newValue: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!`                | The new value of the preference |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|----------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | `true`to update the state of the preference with the new value |