Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [XML Attrs](https://developer.android.com/reference/android/preference/DialogPreference#lattrs) \| [Inherited XML Attrs](https://developer.android.com/reference/android/preference/DialogPreference#inhattrs) \| [Inherited Constants](https://developer.android.com/reference/android/preference/DialogPreference#inhconstants) \| [Ctors](https://developer.android.com/reference/android/preference/DialogPreference#pubctors) \| [Methods](https://developer.android.com/reference/android/preference/DialogPreference#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/preference/DialogPreference#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/preference/DialogPreference#inhmethods)

# DialogPreference

*** ** * ** ***


`
public


abstract
class
DialogPreference
`


`


`

`

extends https://developer.android.com/reference/android/preference/Preference


`

`


implements

https://developer.android.com/reference/android/content/DialogInterface.OnClickListener,

https://developer.android.com/reference/android/content/DialogInterface.OnDismissListener,

https://developer.android.com/reference/android/preference/PreferenceManager.OnActivityDestroyListener


`

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.preference.Preference](https://developer.android.com/reference/android/preference/Preference) ||
|   | ↳ | android.preference.DialogPreference |

|---|
| Known direct subclasses [EditTextPreference](https://developer.android.com/reference/android/preference/EditTextPreference), [ListPreference](https://developer.android.com/reference/android/preference/ListPreference), [MultiSelectListPreference](https://developer.android.com/reference/android/preference/MultiSelectListPreference) |---|---| | [EditTextPreference](https://developer.android.com/reference/android/preference/EditTextPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [ListPreference](https://developer.android.com/reference/android/preference/ListPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [MultiSelectListPreference](https://developer.android.com/reference/android/preference/MultiSelectListPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | |

<br />

*** ** * ** ***


**This class was deprecated
in API level 29.**   

Use the [AndroidX](https://developer.android.com/jetpack/androidx)
[Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on
using the AndroidX Preference Library see
[Settings](https://developer.android.com/guide/topics/ui/settings).

A base class for `https://developer.android.com/reference/android/preference/Preference` objects that are
dialog-based. These preferences will, when clicked, open a dialog showing the
actual preference controls.

## Summary

| ### XML attributes ||
|---|---|
| [`android:dialogIcon`](https://developer.android.com/reference/android/preference/DialogPreference#attr_android:dialogIcon) | The icon for the dialog. |
| [`android:dialogLayout`](https://developer.android.com/reference/android/preference/DialogPreference#attr_android:dialogLayout) | A layout to be used as the content View for the dialog. |
| [`android:dialogMessage`](https://developer.android.com/reference/android/preference/DialogPreference#attr_android:dialogMessage) | The message in the dialog. |
| [`android:dialogTitle`](https://developer.android.com/reference/android/preference/DialogPreference#attr_android:dialogTitle) | The title in the dialog. |
| [`android:negativeButtonText`](https://developer.android.com/reference/android/preference/DialogPreference#attr_android:negativeButtonText) | The negative button text for the dialog. |
| [`android:positiveButtonText`](https://developer.android.com/reference/android/preference/DialogPreference#attr_android:positiveButtonText) | The positive button text for the dialog. |

| ### Inherited XML attributes |
|---|---|
| From class `https://developer.android.com/reference/android/preference/Preference` |---|---| | [`android:defaultValue`](https://developer.android.com/reference/android/preference/Preference#attr_android:defaultValue) | The default value for the preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage. | | [`android:dependency`](https://developer.android.com/reference/android/preference/Preference#attr_android:dependency) | The key of another Preference that this Preference will depend on. | | [`android:enabled`](https://developer.android.com/reference/android/preference/Preference#attr_android:enabled) | Whether the Preference is enabled. | | [`android:fragment`](https://developer.android.com/reference/android/preference/Preference#attr_android:fragment) | When used inside of a modern PreferenceActivity, this declares a new PreferenceFragment to be shown when the user selects this item. | | [`android:icon`](https://developer.android.com/reference/android/preference/Preference#attr_android:icon) | The optional icon for the preference. | | [`android:iconSpaceReserved`](https://developer.android.com/reference/android/preference/Preference#attr_android:iconSpaceReserved) | Whether the space for the preference icon view will be reserved. | | [`android:key`](https://developer.android.com/reference/android/preference/Preference#attr_android:key) | The key to store the Preference value. | | [`android:layout`](https://developer.android.com/reference/android/preference/Preference#attr_android:layout) | The layout for the Preference in a PreferenceActivity screen. | | [`android:order`](https://developer.android.com/reference/android/preference/Preference#attr_android:order) | The order for the Preference (lower values are to be ordered first). | | [`android:persistent`](https://developer.android.com/reference/android/preference/Preference#attr_android:persistent) | Whether the Preference stores its value to the storage. | | [`android:recycleEnabled`](https://developer.android.com/reference/android/preference/Preference#attr_android:recycleEnabled) | Whether the preference has enabled to have its view recycled when used in the list view. | | [`android:selectable`](https://developer.android.com/reference/android/preference/Preference#attr_android:selectable) | Whether the Preference is selectable. | | [`android:shouldDisableView`](https://developer.android.com/reference/android/preference/Preference#attr_android:shouldDisableView) | Whether the view of this Preference should be disabled when this Preference is disabled. | | [`android:singleLineTitle`](https://developer.android.com/reference/android/preference/Preference#attr_android:singleLineTitle) | Whether to use single line for the preference title text. | | [`android:summary`](https://developer.android.com/reference/android/preference/Preference#attr_android:summary) | The summary for the Preference. | | [`android:title`](https://developer.android.com/reference/android/preference/Preference#attr_android:title) | The title for the Preference. | | [`android:widgetLayout`](https://developer.android.com/reference/android/preference/Preference#attr_android:widgetLayout) | The layout for the controllable widget portion of a Preference. | ||

| ### Inherited constants |
|---|
| From class `https://developer.android.com/reference/android/preference/Preference` |---|---| | `int` | `https://developer.android.com/reference/android/preference/Preference#DEFAULT_ORDER` Specify for `https://developer.android.com/reference/android/preference/Preference#setOrder(int)` if a specific order is not required. | |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/preference/DialogPreference#DialogPreference(android.content.Context)(https://developer.android.com/reference/android/content/Context context) ` |
| ` https://developer.android.com/reference/android/preference/DialogPreference#DialogPreference(android.content.Context,%20android.util.AttributeSet)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/util/AttributeSet attrs) ` |
| ` https://developer.android.com/reference/android/preference/DialogPreference#DialogPreference(android.content.Context,%20android.util.AttributeSet,%20int)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/util/AttributeSet attrs, int defStyleAttr) ` |
| ` https://developer.android.com/reference/android/preference/DialogPreference#DialogPreference(android.content.Context,%20android.util.AttributeSet,%20int,%20int)(https://developer.android.com/reference/android/content/Context context, https://developer.android.com/reference/android/util/AttributeSet attrs, int defStyleAttr, int defStyleRes) ` |

| ### Public methods ||
|---|---|
| ` https://developer.android.com/reference/android/app/Dialog` | ` https://developer.android.com/reference/android/preference/DialogPreference#getDialog()() ` Gets the dialog that is shown by this preference. |
| ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/preference/DialogPreference#getDialogIcon()() ` Returns the icon to be shown on subsequent dialogs. |
| ` int` | ` https://developer.android.com/reference/android/preference/DialogPreference#getDialogLayoutResource()() ` Returns the layout resource that is used as the content View for subsequent dialogs. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/DialogPreference#getDialogMessage()() ` Returns the message to be shown on subsequent dialogs. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/DialogPreference#getDialogTitle()() ` Returns the title to be shown on subsequent dialogs. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/DialogPreference#getNegativeButtonText()() ` Returns the text of the negative button to be shown on subsequent dialogs. |
| ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/DialogPreference#getPositiveButtonText()() ` Returns the text of the positive button to be shown on subsequent dialogs. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onActivityDestroy()() ` See Activity's onDestroy. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onClick(android.content.DialogInterface,%20int)(https://developer.android.com/reference/android/content/DialogInterface dialog, int which) ` This method will be invoked when a button in the dialog is clicked. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onDismiss(android.content.DialogInterface)(https://developer.android.com/reference/android/content/DialogInterface dialog) ` This method will be invoked when the dialog is dismissed. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setDialogIcon(int)(int dialogIconRes) ` Sets the icon (resource ID) of the dialog. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setDialogIcon(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable dialogIcon) ` Sets the icon of the dialog. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setDialogLayoutResource(int)(int dialogLayoutResId) ` Sets the layout resource that is inflated as the `https://developer.android.com/reference/android/view/View` to be shown as the content View of subsequent dialogs. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setDialogMessage(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence dialogMessage) ` Sets the message of the dialog. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setDialogMessage(int)(int dialogMessageResId) ` |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setDialogTitle(int)(int dialogTitleResId) ` |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setDialogTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence dialogTitle) ` Sets the title of the dialog. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setNegativeButtonText(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence negativeButtonText) ` Sets the text of the negative button of the dialog. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setNegativeButtonText(int)(int negativeButtonTextResId) ` |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setPositiveButtonText(int)(int positiveButtonTextResId) ` |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#setPositiveButtonText(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence positiveButtonText) ` Sets the text of the positive button of the dialog. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onBindDialogView(android.view.View)(https://developer.android.com/reference/android/view/View view) ` Binds views in the content View of the dialog to data. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onClick()() ` Processes a click on the preference. |
| ` https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/preference/DialogPreference#onCreateDialogView()() ` Creates the content view for the dialog (if a custom content view is required). |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onDialogClosed(boolean)(boolean positiveResult) ` Called when the dialog is dismissed and should be used to save data to the `https://developer.android.com/reference/android/content/SharedPreferences`. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onPrepareDialogBuilder(android.app.AlertDialog.Builder)(https://developer.android.com/reference/android/app/AlertDialog.Builder builder) ` Prepares the dialog builder to be shown when the preference is clicked. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#onRestoreInstanceState(android.os.Parcelable)(https://developer.android.com/reference/android/os/Parcelable state) ` Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`. |
| ` https://developer.android.com/reference/android/os/Parcelable` | ` https://developer.android.com/reference/android/preference/DialogPreference#onSaveInstanceState()() ` Hook allowing a Preference to generate a representation of its internal state that can later be used to create a new instance with that same state. |
| ` void` | ` https://developer.android.com/reference/android/preference/DialogPreference#showDialog(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle state) ` Shows the dialog associated with this Preference. |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/android/preference/Preference ` |---|---| | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#callChangeListener(java.lang.Object)(https://developer.android.com/reference/java/lang/Object newValue) ` Call this method after the user changes the preference, but before the internal state is set. | | ` int` | ` https://developer.android.com/reference/android/preference/Preference#compareTo(android.preference.Preference)(https://developer.android.com/reference/android/preference/Preference another) ` Compares Preference objects based on order (if set), otherwise alphabetically on the titles. | | ` https://developer.android.com/reference/android/preference/Preference` | ` https://developer.android.com/reference/android/preference/Preference#findPreferenceInHierarchy(java.lang.String)(https://developer.android.com/reference/java/lang/String key) ` Finds a Preference in this hierarchy (the whole thing, even above/below your `https://developer.android.com/reference/android/preference/PreferenceScreen` screen break) with the given key. | | ` https://developer.android.com/reference/android/content/Context` | ` https://developer.android.com/reference/android/preference/Preference#getContext()() ` Returns the `https://developer.android.com/reference/android/content/Context` of this Preference. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getDependency()() ` Returns the key of the dependency on this Preference. | | ` https://developer.android.com/reference/android/content/SharedPreferences.Editor` | ` https://developer.android.com/reference/android/preference/Preference#getEditor()() ` Returns an `https://developer.android.com/reference/android/content/SharedPreferences.Editor` where this Preference can save its value(s). | | ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/preference/Preference#getExtras()() ` Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getFragment()() ` Return the fragment class name associated with this Preference. | | ` https://developer.android.com/reference/android/graphics/drawable/Drawable` | ` https://developer.android.com/reference/android/preference/Preference#getIcon()() ` Returns the icon of this Preference. | | ` https://developer.android.com/reference/android/content/Intent` | ` https://developer.android.com/reference/android/preference/Preference#getIntent()() ` Return the `https://developer.android.com/reference/android/content/Intent` associated with this Preference. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getKey()() ` Gets the key for this Preference, which is also the key used for storing values into `https://developer.android.com/reference/android/content/SharedPreferences` or `https://developer.android.com/reference/android/preference/PreferenceDataStore`. | | ` int` | ` https://developer.android.com/reference/android/preference/Preference#getLayoutResource()() ` Gets the layout resource that will be shown as the `https://developer.android.com/reference/android/view/View` for this Preference. | | ` https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener` | ` https://developer.android.com/reference/android/preference/Preference#getOnPreferenceChangeListener()() ` Returns the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated). | | ` https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener` | ` https://developer.android.com/reference/android/preference/Preference#getOnPreferenceClickListener()() ` Returns the callback to be invoked when this Preference is clicked. | | ` int` | ` https://developer.android.com/reference/android/preference/Preference#getOrder()() ` Gets the order of this Preference with respect to other Preference objects on the same level. | | ` https://developer.android.com/reference/android/preference/PreferenceGroup` | ` https://developer.android.com/reference/android/preference/Preference#getParent()() ` Returns the `https://developer.android.com/reference/android/preference/PreferenceGroup` which is this Preference assigned to or `null` if this preference is not assigned to any group or is a root Preference. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedBoolean(boolean)(boolean defaultReturnValue) ` Attempts to get a persisted boolean if this Preference is persistent. | | ` float` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedFloat(float)(float defaultReturnValue) ` Attempts to get a persisted float if this Preference is persistent. | | ` int` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedInt(int)(int defaultReturnValue) ` Attempts to get a persisted int if this Preference is persistent. | | ` long` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedLong(long)(long defaultReturnValue) ` Attempts to get a persisted long if this Preference is persistent. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String)(https://developer.android.com/reference/java/lang/String defaultReturnValue) ` Attempts to get a persisted String if this Preference is persistent. | | ` https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String>` | ` https://developer.android.com/reference/android/preference/Preference#getPersistedStringSet(java.util.Set<java.lang.String>)(https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String> defaultReturnValue) ` Attempts to get a persisted set of Strings if this Preference is persistent. | | ` https://developer.android.com/reference/android/preference/PreferenceDataStore` | ` https://developer.android.com/reference/android/preference/Preference#getPreferenceDataStore()() ` Returns `https://developer.android.com/reference/android/preference/PreferenceDataStore` used by this Preference. | | ` https://developer.android.com/reference/android/preference/PreferenceManager` | ` https://developer.android.com/reference/android/preference/Preference#getPreferenceManager()() ` Gets the `https://developer.android.com/reference/android/preference/PreferenceManager` that manages this Preference object's tree. | | ` https://developer.android.com/reference/android/content/SharedPreferences` | ` https://developer.android.com/reference/android/preference/Preference#getSharedPreferences()() ` Returns the `https://developer.android.com/reference/android/content/SharedPreferences` where this Preference can read its value(s). | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#getShouldDisableView()() ` Checks whether this Preference should disable its view when it's action is disabled. | | ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/Preference#getSummary()() ` Returns the summary of this Preference. | | ` https://developer.android.com/reference/java/lang/CharSequence` | ` https://developer.android.com/reference/android/preference/Preference#getTitle()() ` Returns the title of this Preference. | | ` int` | ` https://developer.android.com/reference/android/preference/Preference#getTitleRes()() ` Returns the title resource ID of this Preference. | | ` https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/preference/Preference#getView(android.view.View,%20android.view.ViewGroup)(https://developer.android.com/reference/android/view/View convertView, https://developer.android.com/reference/android/view/ViewGroup parent) ` Gets the View that will be shown in the `https://developer.android.com/reference/android/preference/PreferenceActivity`. | | ` int` | ` https://developer.android.com/reference/android/preference/Preference#getWidgetLayoutResource()() ` Gets the layout resource for the controllable widget portion of this Preference. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#hasKey()() ` Checks whether this Preference has a valid key. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isEnabled()() ` Checks whether this Preference should be enabled in the list. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isIconSpaceReserved()() ` Gets whether the space this preference icon view is reserved. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isPersistent()() ` Checks whether this Preference is persistent. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isRecycleEnabled()() ` Checks whether this Preference has enabled to have its view recycled when used in the list view. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isSelectable()() ` Checks whether this Preference should be selectable in the list. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#isSingleLineTitle()() ` Gets whether the title of this preference is constrained to a single line. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#notifyChanged()() ` Should be called when the data of this `https://developer.android.com/reference/android/preference/Preference` has changed. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#notifyDependencyChange(boolean)(boolean disableDependents) ` Notifies any listening dependents of a change that affects the dependency. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#notifyHierarchyChanged()() ` Should be called when a Preference has been added/removed from this group, or the ordering should be re-evaluated. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onAttachedToActivity()() ` Called when the Preference hierarchy has been attached to the `https://developer.android.com/reference/android/preference/PreferenceActivity`. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onAttachedToHierarchy(android.preference.PreferenceManager)(https://developer.android.com/reference/android/preference/PreferenceManager preferenceManager) ` Called when this Preference has been attached to a Preference hierarchy. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onBindView(android.view.View)(https://developer.android.com/reference/android/view/View view) ` Binds the created View to the data for this Preference. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onClick()() ` Processes a click on the preference. | | ` https://developer.android.com/reference/android/view/View` | ` https://developer.android.com/reference/android/preference/Preference#onCreateView(android.view.ViewGroup)(https://developer.android.com/reference/android/view/ViewGroup parent) ` Creates the View to be shown for this Preference in the `https://developer.android.com/reference/android/preference/PreferenceActivity`. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onDependencyChanged(android.preference.Preference,%20boolean)(https://developer.android.com/reference/android/preference/Preference dependency, boolean disableDependent) ` Called when the dependency changes. | | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/android/preference/Preference#onGetDefaultValue(android.content.res.TypedArray,%20int)(https://developer.android.com/reference/android/content/res/TypedArray a, int index) ` Called when a Preference is being inflated and the default value attribute needs to be read. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onParentChanged(android.preference.Preference,%20boolean)(https://developer.android.com/reference/android/preference/Preference parent, boolean disableChild) ` Called when the implicit parent dependency changes. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onPrepareForRemoval()() ` Called when this Preference is being removed from the hierarchy. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onRestoreInstanceState(android.os.Parcelable)(https://developer.android.com/reference/android/os/Parcelable state) ` Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`. | | ` https://developer.android.com/reference/android/os/Parcelable` | ` https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()() ` Hook allowing a Preference to generate a representation of its internal state that can later be used to create a new instance with that same state. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#onSetInitialValue(boolean,%20java.lang.Object)(boolean restorePersistedValue, https://developer.android.com/reference/java/lang/Object defaultValue) ` Implement this to set the initial value of the Preference. | | ` https://developer.android.com/reference/android/os/Bundle` | ` https://developer.android.com/reference/android/preference/Preference#peekExtras()() ` Return the extras Bundle object associated with this preference, returning `null` if there is not currently one. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistBoolean(boolean)(boolean value) ` Attempts to persist a boolean if this Preference is persistent. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistFloat(float)(float value) ` Attempts to persist a long if this Preference is persistent. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistInt(int)(int value) ` Attempts to persist an int if this Preference is persistent. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistLong(long)(long value) ` Attempts to persist a long if this Preference is persistent. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String)(https://developer.android.com/reference/java/lang/String value) ` Attempts to persist a String if this Preference is persistent. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#persistStringSet(java.util.Set<java.lang.String>)(https://developer.android.com/reference/java/util/Set<https://developer.android.com/reference/java/lang/String> values) ` Attempts to persist a set of Strings if this Preference is persistent. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#restoreHierarchyState(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle container) ` Restore this Preference hierarchy's previously saved state from the given container. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#saveHierarchyState(android.os.Bundle)(https://developer.android.com/reference/android/os/Bundle container) ` Store this Preference hierarchy's frozen state into the given container. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setDefaultValue(java.lang.Object)(https://developer.android.com/reference/java/lang/Object defaultValue) ` Sets the default value for this Preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setDependency(java.lang.String)(https://developer.android.com/reference/java/lang/String dependencyKey) ` Sets the key of a Preference that this Preference will depend on. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setEnabled(boolean)(boolean enabled) ` Sets whether this Preference is enabled. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setFragment(java.lang.String)(https://developer.android.com/reference/java/lang/String fragment) ` Sets the class name of a fragment to be shown when this Preference is clicked. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIcon(android.graphics.drawable.Drawable)(https://developer.android.com/reference/android/graphics/drawable/Drawable icon) ` Sets the icon for this Preference with a Drawable. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIcon(int)(int iconResId) ` Sets the icon for this Preference with a resource ID. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIconSpaceReserved(boolean)(boolean iconSpaceReserved) ` Sets whether to reserve the space of this Preference icon view when no icon is provided. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setIntent(android.content.Intent)(https://developer.android.com/reference/android/content/Intent intent) ` Sets an `https://developer.android.com/reference/android/content/Intent` to be used for `https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)` when this Preference is clicked. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setKey(java.lang.String)(https://developer.android.com/reference/java/lang/String key) ` Sets the key for this Preference, which is used as a key to the `https://developer.android.com/reference/android/content/SharedPreferences` or `https://developer.android.com/reference/android/preference/PreferenceDataStore`. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setLayoutResource(int)(int layoutResId) ` Sets the layout resource that is inflated as the `https://developer.android.com/reference/android/view/View` to be shown for this Preference. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setOnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener)(https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener onPreferenceChangeListener) ` Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated). | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setOnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener)(https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener onPreferenceClickListener) ` Sets the callback to be invoked when this Preference is clicked. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setOrder(int)(int order) ` Sets the order of this Preference with respect to other Preference objects on the same level. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setPersistent(boolean)(boolean persistent) ` Sets whether this Preference is persistent. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setPreferenceDataStore(android.preference.PreferenceDataStore)(https://developer.android.com/reference/android/preference/PreferenceDataStore dataStore) ` Sets a `https://developer.android.com/reference/android/preference/PreferenceDataStore` to be used by this Preference instead of using `https://developer.android.com/reference/android/content/SharedPreferences`. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setRecycleEnabled(boolean)(boolean enabled) ` Sets whether this Preference has enabled to have its view recycled when used in the list view. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSelectable(boolean)(boolean selectable) ` Sets whether this Preference is selectable. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setShouldDisableView(boolean)(boolean shouldDisableView) ` Sets whether this Preference should disable its view when it gets disabled. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSingleLineTitle(boolean)(boolean singleLineTitle) ` Sets whether to constrain the title of this Preference to a single line instead of letting it wrap onto multiple lines. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSummary(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence summary) ` Sets the summary for this Preference with a CharSequence. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setSummary(int)(int summaryResId) ` Sets the summary for this Preference with a resource ID. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setTitle(java.lang.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence title) ` Sets the title for this Preference with a CharSequence. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setTitle(int)(int titleResId) ` Sets the title for this Preference with a resource ID. | | ` void` | ` https://developer.android.com/reference/android/preference/Preference#setWidgetLayoutResource(int)(int widgetLayoutResId) ` Sets the layout for the controllable widget portion of this Preference. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#shouldCommit()() ` Returns whether the `https://developer.android.com/reference/android/preference/Preference` should commit its saved value(s) in `https://developer.android.com/reference/android/preference/Preference#getEditor()`. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#shouldDisableDependents()() ` Checks whether this preference's dependents should currently be disabled. | | ` boolean` | ` https://developer.android.com/reference/android/preference/Preference#shouldPersist()() ` Checks whether, at the given time this method is called, this Preference should store/restore its value(s) into the `https://developer.android.com/reference/android/content/SharedPreferences` or into `https://developer.android.com/reference/android/preference/PreferenceDataStore` if assigned. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/preference/Preference#toString()() ` Returns a string representation of the object. | ||
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||
| From interface ` https://developer.android.com/reference/java/lang/Comparable ` |---|---| | ` abstract int` | ` https://developer.android.com/reference/java/lang/Comparable#compareTo(T)(https://developer.android.com/reference/android/preference/Preference o) ` Compares this object with the specified object for order. | ||
| From interface ` https://developer.android.com/reference/android/content/DialogInterface.OnClickListener ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/android/content/DialogInterface.OnClickListener#onClick(android.content.DialogInterface,%20int)(https://developer.android.com/reference/android/content/DialogInterface dialog, int which) ` This method will be invoked when a button in the dialog is clicked. | ||
| From interface ` https://developer.android.com/reference/android/content/DialogInterface.OnDismissListener ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/android/content/DialogInterface.OnDismissListener#onDismiss(android.content.DialogInterface)(https://developer.android.com/reference/android/content/DialogInterface dialog) ` This method will be invoked when the dialog is dismissed. | ||
| From interface ` https://developer.android.com/reference/android/preference/PreferenceManager.OnActivityDestroyListener ` |---|---| | ` abstract void` | ` https://developer.android.com/reference/android/preference/PreferenceManager.OnActivityDestroyListener#onActivityDestroy()() ` See Activity's onDestroy. | ||

## XML attributes

### android:dialogIcon

The icon for the dialog.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

<br />

### android:dialogLayout

A layout to be used as the content View for the dialog. By default, this shouldn't
be needed. If a custom DialogPreference is required, this should be set. For example,
the EditTextPreference uses a layout with an EditText as this attribute.

May be a reference to another resource, in the form
"`@[+][*package*:]*type*/*name*`" or a theme
attribute in the form
"`?[*package*:]*type*/*name*`".

<br />

### android:dialogMessage

The message in the dialog. If a dialogLayout is provided and contains
a TextView with ID android:id/message, this message will be placed in there.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:dialogTitle

The title in the dialog.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:negativeButtonText

The negative button text for the dialog. Set to @null to hide the negative button.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

### android:positiveButtonText

The positive button text for the dialog. Set to @null to hide the positive button.

May be a string value, using '\\\\;' to escape characters such as
'\\\\n' or '\\\\uxxxx' for a unicode character;

<br />

## Public constructors

### DialogPreference

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DialogPreference (Context context)
```

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |

### DialogPreference

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DialogPreference (Context context, 
                AttributeSet attrs)
```

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `attrs` | `AttributeSet` <br /> |

### DialogPreference

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DialogPreference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)
```

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `attrs` | `AttributeSet` <br /> |
| `defStyleAttr` | `int` <br /> |

### DialogPreference

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public DialogPreference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)
```

<br />

<br />

| Parameters ||
|---|---|
| `context` | `Context` <br /> |
| `attrs` | `AttributeSet` <br /> |
| `defStyleAttr` | `int` <br /> |
| `defStyleRes` | `int` <br /> |

## Public methods

### getDialog

Added in [API level 3](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Dialog getDialog ()
```

Gets the dialog that is shown by this preference.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/app/Dialog` | The dialog, or null if a dialog is not being shown. <br /> |

### getDialogIcon

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Drawable getDialogIcon ()
```

Returns the icon to be shown on subsequent dialogs.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable` | The icon, as a `https://developer.android.com/reference/android/graphics/drawable/Drawable`. <br /> |

### getDialogLayoutResource

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public int getDialogLayoutResource ()
```

Returns the layout resource that is used as the content View for
subsequent dialogs.

<br />

| Returns ||
|---|---|
| `int` | The layout resource. <br /> |

### getDialogMessage

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getDialogMessage ()
```

Returns the message to be shown on subsequent dialogs.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | The message. <br /> |

### getDialogTitle

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getDialogTitle ()
```

Returns the title to be shown on subsequent dialogs.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | The title. <br /> |

### getNegativeButtonText

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getNegativeButtonText ()
```

Returns the text of the negative button to be shown on subsequent
dialogs.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | The text of the negative button. <br /> |

### getPositiveButtonText

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public CharSequence getPositiveButtonText ()
```

Returns the text of the positive button to be shown on subsequent
dialogs.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/CharSequence` | The text of the positive button. <br /> |

### onActivityDestroy

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onActivityDestroy ()
```

See Activity's onDestroy.

<br />

### onClick

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onClick (DialogInterface dialog, 
                int which)
```

This method will be invoked when a button in the dialog is clicked.

<br />

| Parameters ||
|---|---|
| `dialog` | `DialogInterface`: the dialog that received the click <br /> |
| `which` | `int`: the button that was clicked (ex. `https://developer.android.com/reference/android/content/DialogInterface#BUTTON_POSITIVE`) or the position of the item clicked <br /> |

### onDismiss

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void onDismiss (DialogInterface dialog)
```

This method will be invoked when the dialog is dismissed.

<br />

| Parameters ||
|---|---|
| `dialog` | `DialogInterface`: the dialog that was dismissed will be passed into the method <br /> |

### setDialogIcon

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDialogIcon (int dialogIconRes)
```

Sets the icon (resource ID) of the dialog. This will be shown on
subsequent dialogs.

<br />

| Parameters ||
|---|---|
| `dialogIconRes` | `int`: The icon, as a resource ID. <br /> |

### setDialogIcon

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDialogIcon (Drawable dialogIcon)
```

Sets the icon of the dialog. This will be shown on subsequent dialogs.

<br />

| Parameters ||
|---|---|
| `dialogIcon` | `Drawable`: The icon, as a `https://developer.android.com/reference/android/graphics/drawable/Drawable`. <br /> |

### setDialogLayoutResource

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDialogLayoutResource (int dialogLayoutResId)
```

Sets the layout resource that is inflated as the `https://developer.android.com/reference/android/view/View` to be shown
as the content View of subsequent dialogs.

<br />

| Parameters ||
|---|---|
| `dialogLayoutResId` | `int`: The layout resource ID to be inflated. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/DialogPreference#setDialogMessage(java.lang.CharSequence)`

### setDialogMessage

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDialogMessage (CharSequence dialogMessage)
```

Sets the message of the dialog. This will be shown on subsequent dialogs.


This message forms the content View of the dialog and conflicts with
list-based dialogs, for example. If setting a custom View on a dialog via
`https://developer.android.com/reference/android/preference/DialogPreference#setDialogLayoutResource(int)`, include a text View with ID
`https://developer.android.com/reference/android/R.id#message` and it will be populated with this message.

<br />

| Parameters ||
|---|---|
| `dialogMessage` | `CharSequence`: The message. <br /> |

### setDialogMessage

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDialogMessage (int dialogMessageResId)
```

<br />

<br />

| Parameters ||
|---|---|
| `dialogMessageResId` | `int`: The dialog message as a resource. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/DialogPreference#setDialogMessage(java.lang.CharSequence)`

### setDialogTitle

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDialogTitle (int dialogTitleResId)
```

<br />

<br />

| Parameters ||
|---|---|
| `dialogTitleResId` | `int`: The dialog title as a resource. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/DialogPreference#setDialogTitle(java.lang.CharSequence)`

### setDialogTitle

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setDialogTitle (CharSequence dialogTitle)
```

Sets the title of the dialog. This will be shown on subsequent dialogs.

<br />

| Parameters ||
|---|---|
| `dialogTitle` | `CharSequence`: The title. <br /> |

### setNegativeButtonText

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setNegativeButtonText (CharSequence negativeButtonText)
```

Sets the text of the negative button of the dialog. This will be shown on
subsequent dialogs.

<br />

| Parameters ||
|---|---|
| `negativeButtonText` | `CharSequence`: The text of the negative button. <br /> |

### setNegativeButtonText

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setNegativeButtonText (int negativeButtonTextResId)
```

<br />

<br />

| Parameters ||
|---|---|
| `negativeButtonTextResId` | `int`: The negative button text as a resource. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/DialogPreference#setNegativeButtonText(java.lang.CharSequence)`

### setPositiveButtonText

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setPositiveButtonText (int positiveButtonTextResId)
```

<br />

<br />

| Parameters ||
|---|---|
| `positiveButtonTextResId` | `int`: The positive button text as a resource. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/DialogPreference#setPositiveButtonText(java.lang.CharSequence)`

### setPositiveButtonText

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setPositiveButtonText (CharSequence positiveButtonText)
```

Sets the text of the positive button of the dialog. This will be shown on
subsequent dialogs.

<br />

| Parameters ||
|---|---|
| `positiveButtonText` | `CharSequence`: The text of the positive button. <br /> |

## Protected methods

### onBindDialogView

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onBindDialogView (View view)
```

Binds views in the content View of the dialog to data.


Make sure to call through to the superclass implementation.


If you override this method you *must* call through to the
superclass implementation.

<br />

| Parameters ||
|---|---|
| `view` | `View`: The content View of the dialog, if it is custom. <br /> |

### onClick

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onClick ()
```

Processes a click on the preference. This includes saving the value to
the `https://developer.android.com/reference/android/content/SharedPreferences`. However, the overridden method should
call `https://developer.android.com/reference/android/preference/Preference#callChangeListener(java.lang.Object)` to make sure the client wants to
update the preference's state with the new value.

<br />

### onCreateDialogView

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected View onCreateDialogView ()
```

Creates the content view for the dialog (if a custom content view is
required). By default, it inflates the dialog layout resource if it is
set.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/view/View` | The content View for the dialog. <br /> |

**See also:**

- `https://developer.android.com/reference/android/preference/Preference#setLayoutResource(int)`

### onDialogClosed

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onDialogClosed (boolean positiveResult)
```

Called when the dialog is dismissed and should be used to save data to
the `https://developer.android.com/reference/android/content/SharedPreferences`.

<br />

| Parameters ||
|---|---|
| `positiveResult` | `boolean`: Whether the positive button was clicked (true), or the negative button was clicked or the dialog was canceled (false). <br /> |

### onPrepareDialogBuilder

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onPrepareDialogBuilder (AlertDialog.Builder builder)
```

Prepares the dialog builder to be shown when the preference is clicked.
Use this to set custom properties on the dialog.


Do not `https://developer.android.com/reference/android/app/AlertDialog.Builder#create()` or
`https://developer.android.com/reference/android/app/AlertDialog.Builder#show()`.

<br />

| Parameters ||
|---|---|
| `builder` | `AlertDialog.Builder` <br /> |

### onRestoreInstanceState

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void onRestoreInstanceState (Parcelable state)
```

Hook allowing a Preference to re-apply a representation of its internal state that had
previously been generated by `https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()`. This function will never be called
with a `null` state.

<br />

| Parameters ||
|---|---|
| `state` | `Parcelable`: The saved state that had previously been returned by `https://developer.android.com/reference/android/preference/DialogPreference#onSaveInstanceState()`. <br /> |

### onSaveInstanceState

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected Parcelable onSaveInstanceState ()
```

Hook allowing a Preference to generate a representation of its internal
state that can later be used to create a new instance with that same
state. This state should only contain information that is not persistent
or can be reconstructed later.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/os/Parcelable` | A Parcelable object containing the current dynamic state of this Preference, or `null` if there is nothing interesting to save. The default implementation returns `null`. <br /> |

### showDialog

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
protected void showDialog (Bundle state)
```

Shows the dialog associated with this Preference. This is normally initiated
automatically on clicking on the preference. Call this method if you need to
show the dialog on some other event.

<br />

| Parameters ||
|---|---|
| `state` | `Bundle`: Optional instance state to restore on the dialog <br /> |