Most visited

Recently visited

Added in API level 1

DialogPreference

public abstract class DialogPreference
extends Preference implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, PreferenceManager.OnActivityDestroyListener

java.lang.Object
   ↳ android.preference.Preference
     ↳ android.preference.DialogPreference
Known Direct Subclasses


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

From class android.preference.Preference

Inherited constants

From class android.preference.Preference

Public constructors

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

Public methods

Dialog getDialog()

Gets the dialog that is shown by this preference.

Drawable getDialogIcon()

Returns the icon to be shown on subsequent dialogs.

int getDialogLayoutResource()

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

CharSequence getDialogMessage()

Returns the message to be shown on subsequent dialogs.

CharSequence getDialogTitle()

Returns the title to be shown on subsequent dialogs.

CharSequence getNegativeButtonText()

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

CharSequence getPositiveButtonText()

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

void onActivityDestroy()

See Activity's onDestroy.

void onClick(DialogInterface dialog, int which)

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

void onDismiss(DialogInterface dialog)

This method will be invoked when the dialog is dismissed.

void setDialogIcon(int dialogIconRes)

Sets the icon (resource ID) of the dialog.

void setDialogIcon(Drawable dialogIcon)

Sets the icon of the dialog.

void setDialogLayoutResource(int dialogLayoutResId)

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

void setDialogMessage(CharSequence dialogMessage)

Sets the message of the dialog.

void setDialogMessage(int dialogMessageResId)
void setDialogTitle(int dialogTitleResId)
void setDialogTitle(CharSequence dialogTitle)

Sets the title of the dialog.

void setNegativeButtonText(CharSequence negativeButtonText)

Sets the text of the negative button of the dialog.

void setNegativeButtonText(int negativeButtonTextResId)
void setPositiveButtonText(int positiveButtonTextResId)
void setPositiveButtonText(CharSequence positiveButtonText)

Sets the text of the positive button of the dialog.

Protected methods

void onBindDialogView(View view)

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

void onClick()

Processes a click on the preference.

View onCreateDialogView()

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

void onDialogClosed(boolean positiveResult)

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

void onPrepareDialogBuilder(AlertDialog.Builder builder)

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

void onRestoreInstanceState(Parcelable state)

Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().

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.

void showDialog(Bundle state)

Shows the dialog associated with this Preference.

Inherited methods

From class android.preference.Preference
From class java.lang.Object
From interface java.lang.Comparable
From interface android.content.DialogInterface.OnClickListener
From interface android.content.DialogInterface.OnDismissListener
From interface android.preference.PreferenceManager.OnActivityDestroyListener

XML attributes

android:dialogIcon

The icon for the dialog.

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

This corresponds to the global attribute resource symbol dialogIcon.

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.

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

This corresponds to the global attribute resource symbol dialogLayout.

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.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol dialogMessage.

android:dialogTitle

The title in the dialog.

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol dialogTitle.

android:negativeButtonText

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

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol negativeButtonText.

android:positiveButtonText

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

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

This may also be a reference to a resource (in the form "@[package:]type:name") or theme attribute (in the form "?[package:][type:]name") containing a value of this type.

This corresponds to the global attribute resource symbol positiveButtonText.

Public constructors

DialogPreference

Added in API level 21
DialogPreference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)

Parameters
context Context
attrs AttributeSet
defStyleAttr int
defStyleRes int

DialogPreference

Added in API level 1
DialogPreference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)

Parameters
context Context
attrs AttributeSet
defStyleAttr int

DialogPreference

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

Parameters
context Context
attrs AttributeSet

DialogPreference

Added in API level 21
DialogPreference (Context context)

Parameters
context Context

Public methods

getDialog

Added in API level 3
Dialog getDialog ()

Gets the dialog that is shown by this preference.

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

getDialogIcon

Added in API level 1
Drawable getDialogIcon ()

Returns the icon to be shown on subsequent dialogs.

Returns
Drawable The icon, as a Drawable.

getDialogLayoutResource

Added in API level 1
int getDialogLayoutResource ()

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

Returns
int The layout resource.

getDialogMessage

Added in API level 1
CharSequence getDialogMessage ()

Returns the message to be shown on subsequent dialogs.

Returns
CharSequence The message.

getDialogTitle

Added in API level 1
CharSequence getDialogTitle ()

Returns the title to be shown on subsequent dialogs.

Returns
CharSequence The title.

getNegativeButtonText

Added in API level 1
CharSequence getNegativeButtonText ()

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

Returns
CharSequence The text of the negative button.

getPositiveButtonText

Added in API level 1
CharSequence getPositiveButtonText ()

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

Returns
CharSequence The text of the positive button.

onActivityDestroy

Added in API level 1
void onActivityDestroy ()

See Activity's onDestroy.

onClick

Added in API level 1
void onClick (DialogInterface dialog, 
                int which)

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

Parameters
dialog DialogInterface: The dialog that received the click.
which int: The button that was clicked (e.g. BUTTON1) or the position of the item clicked.

onDismiss

Added in API level 1
void onDismiss (DialogInterface dialog)

This method will be invoked when the dialog is dismissed.

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

setDialogIcon

Added in API level 1
void setDialogIcon (int dialogIconRes)

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

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

setDialogIcon

Added in API level 1
void setDialogIcon (Drawable dialogIcon)

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

Parameters
dialogIcon Drawable: The icon, as a Drawable.

setDialogLayoutResource

Added in API level 1
void setDialogLayoutResource (int dialogLayoutResId)

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.

See also:

setDialogMessage

Added in API level 1
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 setDialogLayoutResource(int), include a text View with ID message and it will be populated with this message.

Parameters
dialogMessage CharSequence: The message.

setDialogMessage

Added in API level 1
void setDialogMessage (int dialogMessageResId)

Parameters
dialogMessageResId int: The dialog message as a resource.

See also:

setDialogTitle

Added in API level 1
void setDialogTitle (int dialogTitleResId)

Parameters
dialogTitleResId int: The dialog title as a resource.

See also:

setDialogTitle

Added in API level 1
void setDialogTitle (CharSequence dialogTitle)

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

Parameters
dialogTitle CharSequence: The title.

setNegativeButtonText

Added in API level 1
void setNegativeButtonText (CharSequence negativeButtonText)

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
void setNegativeButtonText (int negativeButtonTextResId)

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

See also:

setPositiveButtonText

Added in API level 1
void setPositiveButtonText (int positiveButtonTextResId)

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

See also:

setPositiveButtonText

Added in API level 1
void setPositiveButtonText (CharSequence positiveButtonText)

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.

Protected methods

onBindDialogView

Added in API level 1
void onBindDialogView (View view)

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

Make sure to 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
void onClick ()

Processes a click on the preference. This includes saving the value to the SharedPreferences. However, the overridden method should call callChangeListener(Object) to make sure the client wants to update the preference's state with the new value.

onCreateDialogView

Added in API level 1
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.

Returns
View The content View for the dialog.

See also:

onDialogClosed

Added in API level 1
void onDialogClosed (boolean positiveResult)

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
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 create() or show().

Parameters
builder AlertDialog.Builder

onRestoreInstanceState

Added in API level 1
void onRestoreInstanceState (Parcelable state)

Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState(). This function will never be called with a null state.

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

onSaveInstanceState

Added in API level 1
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.

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

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

Hooray!