Added in API level 1
Deprecated in API level 29

DialogPreference


abstract class DialogPreference : Preference, DialogInterface.OnClickListener, DialogInterface.OnDismissListener, PreferenceManager.OnActivityDestroyListener
kotlin.Any
   ↳ android.preference.Preference
   ↳ android.preference.DialogPreference

A base class for Preference objects that are dialog-based. These preferences will, when clicked, open a dialog showing the actual preference controls.

Summary

XML attributes
android:dialogIcon The icon for the dialog.
android:dialogLayout A layout to be used as the content View for the dialog.
android:dialogMessage The message in the dialog.
android:dialogTitle The title in the dialog.
android:negativeButtonText The negative button text for the dialog.
android:positiveButtonText The positive button text for the dialog.
Inherited XML attributes
Inherited constants
Public constructors
DialogPreference(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

DialogPreference(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

DialogPreference(context: Context!, attrs: AttributeSet!)

Public methods
open Dialog!

Gets the dialog that is shown by this preference.

open Drawable!

Returns the icon to be shown on subsequent dialogs.

open Int

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

open CharSequence!

Returns the message to be shown on subsequent dialogs.

open CharSequence!

Returns the title to be shown on subsequent dialogs.

open CharSequence!

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

open CharSequence!

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

open Unit

See Activity's onDestroy.

open Unit
onClick(dialog: DialogInterface!, which: Int)

open Unit

open Unit
setDialogIcon(dialogIcon: Drawable!)

Sets the icon of the dialog.

open Unit
setDialogIcon(dialogIconRes: Int)

Sets the icon (resource ID) of the dialog.

open Unit
setDialogLayoutResource(dialogLayoutResId: Int)

Sets the layout resource that is inflated as the View to be shown as the content View of subsequent dialogs.

open Unit
setDialogMessage(dialogMessage: CharSequence!)

Sets the message of the dialog.

open Unit
setDialogMessage(dialogMessageResId: Int)

open Unit

Sets the title of the dialog.

open Unit
setDialogTitle(dialogTitleResId: Int)

open Unit
setNegativeButtonText(negativeButtonText: CharSequence!)

Sets the text of the negative button of the dialog.

open Unit
setNegativeButtonText(negativeButtonTextResId: Int)

open Unit
setPositiveButtonText(positiveButtonText: CharSequence!)

Sets the text of the positive button of the dialog.

open Unit
setPositiveButtonText(positiveButtonTextResId: Int)

Protected methods
open Unit

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

open Unit

open View!

Creates the content view for the dialog (if a custom content view is required).

open Unit
onDialogClosed(positiveResult: Boolean)

Called when the dialog is dismissed and should be used to save data to the SharedPreferences.

open Unit

Prepares the dialog builder to be shown when the preference is clicked.

open Unit

open Parcelable!

open Unit
showDialog(state: Bundle!)

Shows the dialog associated with this Preference.

Inherited functions

XML attributes

android:dialogIcon

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".

android:dialogLayout

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".

android:dialogMessage

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;

android:dialogTitle

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;

android:negativeButtonText

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;

android:positiveButtonText

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;

Public constructors

DialogPreference

Added in API level 21
DialogPreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

DialogPreference

Added in API level 1
DialogPreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

DialogPreference

Added in API level 1
DialogPreference(
    context: Context!,
    attrs: AttributeSet!)

DialogPreference

Added in API level 21
DialogPreference(context: Context!)

Public methods

getDialog

Added in API level 3
Deprecated in API level 29
open fun getDialog(): Dialog!

Deprecated: Deprecated in Java.

Gets the dialog that is shown by this preference.

Return
Dialog! The dialog, or null if a dialog is not being shown.

getDialogIcon

Added in API level 1
open fun getDialogIcon(): Drawable!

Deprecated: Deprecated in Java.

Returns the icon to be shown on subsequent dialogs.

Return
Drawable! The icon, as a Drawable.

getDialogLayoutResource

Added in API level 1
open fun getDialogLayoutResource(): Int

Deprecated: Deprecated in Java.

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

Return
Int The layout resource.

getDialogMessage

Added in API level 1
open fun getDialogMessage(): CharSequence!

Deprecated: Deprecated in Java.

Returns the message to be shown on subsequent dialogs.

Return
CharSequence! The message.

getDialogTitle

Added in API level 1
open fun getDialogTitle(): CharSequence!

Deprecated: Deprecated in Java.

Returns the title to be shown on subsequent dialogs.

Return
CharSequence! The title.

getNegativeButtonText

Added in API level 1
open fun getNegativeButtonText(): CharSequence!

Deprecated: Deprecated in Java.

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

Return
CharSequence! The text of the negative button.

getPositiveButtonText

Added in API level 1
open fun getPositiveButtonText(): CharSequence!

Deprecated: Deprecated in Java.

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

Return
CharSequence! The text of the positive button.

onActivityDestroy

Added in API level 1
open fun onActivityDestroy(): Unit

Deprecated: Deprecated in Java.

See Activity's onDestroy.

onClick

Added in API level 1
open fun onClick(
    dialog: DialogInterface!,
    which: Int
): Unit

Deprecated: Deprecated in Java.

Parameters
dialog DialogInterface!: the dialog that received the click
which Int: the button that was clicked (ex. DialogInterface#BUTTON_POSITIVE) or the position of the item clicked

onDismiss

Added in API level 1
open fun onDismiss(dialog: DialogInterface!): Unit

Deprecated: Deprecated in Java.

Parameters
dialog DialogInterface!: the dialog that was dismissed will be passed into the method

setDialogIcon

Added in API level 1
open fun setDialogIcon(dialogIcon: Drawable!): Unit

Deprecated: Deprecated in Java.

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

Parameters
dialogIcon Drawable!: The icon, as a Drawable.

setDialogIcon

Added in API level 1
open fun setDialogIcon(dialogIconRes: Int): Unit

Deprecated: Deprecated in Java.

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

Parameters
dialogIconRes Int: The icon, as a resource ID.

setDialogLayoutResource

Added in API level 1
open fun setDialogLayoutResource(dialogLayoutResId: Int): Unit

Deprecated: Deprecated in Java.

Sets the layout resource that is inflated as the View to be shown as the content View of subsequent dialogs.

Parameters
dialogLayoutResId Int: The layout resource ID to be inflated.

setDialogMessage

Added in API level 1
open fun setDialogMessage(dialogMessage: CharSequence!): Unit

Deprecated: Deprecated in Java.

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 setDialogLayoutResource(int), include a text View with ID android.R.id#message and it will be populated with this message.

Parameters
dialogMessage CharSequence!: The message.

setDialogMessage

Added in API level 1
open fun setDialogMessage(dialogMessageResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
dialogMessageResId Int: The dialog message as a resource.

setDialogTitle

Added in API level 1
open fun setDialogTitle(dialogTitle: CharSequence!): Unit

Deprecated: Deprecated in Java.

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

Parameters
dialogTitle CharSequence!: The title.

setDialogTitle

Added in API level 1
open fun setDialogTitle(dialogTitleResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
dialogTitleResId Int: The dialog title as a resource.

setNegativeButtonText

Added in API level 1
open fun setNegativeButtonText(negativeButtonText: CharSequence!): Unit

Deprecated: Deprecated in Java.

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

Parameters
negativeButtonText CharSequence!: The text of the negative button.

setNegativeButtonText

Added in API level 1
open fun setNegativeButtonText(negativeButtonTextResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
negativeButtonTextResId Int: The negative button text as a resource.

setPositiveButtonText

Added in API level 1
open fun setPositiveButtonText(positiveButtonText: CharSequence!): Unit

Deprecated: Deprecated in Java.

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

Parameters
positiveButtonText CharSequence!: The text of the positive button.

setPositiveButtonText

Added in API level 1
open fun setPositiveButtonText(positiveButtonTextResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
positiveButtonTextResId Int: The positive button text as a resource.

Protected methods

onBindDialogView

Added in API level 1
protected open fun onBindDialogView(view: View!): Unit

Deprecated: Deprecated in Java.

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.

Parameters
view View!: The content View of the dialog, if it is custom.

onClick

Added in API level 1
protected open fun onClick(): Unit

Deprecated: Deprecated in Java.

onCreateDialogView

Added in API level 1
protected open fun onCreateDialogView(): View!

Deprecated: Deprecated in Java.

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.

Return
View! The content View for the dialog.

onDialogClosed

Added in API level 1
protected open fun onDialogClosed(positiveResult: Boolean): Unit

Deprecated: Deprecated in Java.

Called when the dialog is dismissed and should be used to save data to the SharedPreferences.

Parameters
positiveResult Boolean: Whether the positive button was clicked (true), or the negative button was clicked or the dialog was canceled (false).

onPrepareDialogBuilder

Added in API level 1
protected open fun onPrepareDialogBuilder(builder: AlertDialog.Builder!): Unit

Deprecated: Deprecated in Java.

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

Do not AlertDialog.Builder#create() or AlertDialog.Builder#show().

onRestoreInstanceState

Added in API level 1
protected open fun onRestoreInstanceState(state: Parcelable!): Unit

Deprecated: Deprecated in Java.

Parameters
state Parcelable!: The saved state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

Added in API level 1
protected open fun onSaveInstanceState(): Parcelable!

Deprecated: Deprecated in Java.

Return
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.

showDialog

Added in API level 1
protected open fun showDialog(state: Bundle!): Unit

Deprecated: Deprecated in Java.

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.

Parameters
state Bundle!: Optional instance state to restore on the dialog