Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

OnPreferenceChangeListener

interface OnPreferenceChangeListener
androidx.preference.Preference.OnPreferenceChangeListener

Interface definition for a callback to be invoked when the value of this 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 methods

abstract Boolean
onPreferenceChange(preference: Preference!, newValue: Any!)

Called when a preference has been changed by the user.

Public methods

onPreferenceChange

abstract 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!: The changed preference
newValue Preference!: The new value of the preference
Return
Boolean: true to update the state of the preference with the new value