lightbulb_outline Please take our October 2018 developer survey. Start survey
added in version 1.0.0
belongs to Maven artifact androidx.preference:preference:1.0.0

PreferenceDialogFragment

public abstract class PreferenceDialogFragment
extends DialogFragment implements DialogInterface.OnClickListener

java.lang.Object
   ↳ android.app.Fragment
     ↳ android.app.DialogFragment
       ↳ androidx.preference.PreferenceDialogFragment


Abstract base class which presents a dialog associated with a DialogPreference. Since the preference object may not be available during fragment re-creation, the necessary information for displaying the dialog is read once during the initial call to onCreate(Bundle) and saved/restored in the saved instance state. Custom subclasses should also follow this pattern.

Summary

Constants

String ARG_KEY

Inherited constants

Public constructors

PreferenceDialogFragment()

Public methods

DialogPreference getPreference()

Get the preference that requested this dialog.

void onClick(DialogInterface dialog, int which)
void onCreate(Bundle savedInstanceState)
Dialog onCreateDialog(Bundle savedInstanceState)
abstract void onDialogClosed(boolean positiveResult)
void onDismiss(DialogInterface dialog)
void onSaveInstanceState(Bundle outState)

Protected methods

void onBindDialogView(View view)

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

View onCreateDialogView(Context context)

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

void onPrepareDialogBuilder(AlertDialog.Builder builder)

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

Inherited methods

Constants

ARG_KEY

added in version 1.0.0
protected static final String ARG_KEY

Constant Value: "key"

Public constructors

PreferenceDialogFragment

added in version 1.0.0
public PreferenceDialogFragment ()

Public methods

getPreference

added in version 1.0.0
public DialogPreference getPreference ()

Get the preference that requested this dialog. Available after onCreate(Bundle) has been called on the PreferenceFragment which launched this dialog.

Returns
DialogPreference The DialogPreference associated with this dialog.

onClick

added in version 1.0.0
public void onClick (DialogInterface dialog, 
                int which)

Parameters
dialog DialogInterface

which int

onCreate

public void onCreate (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

onCreateDialog

public Dialog onCreateDialog (Bundle savedInstanceState)

Parameters
savedInstanceState Bundle

Returns
Dialog

onDialogClosed

added in version 1.0.0
public abstract void onDialogClosed (boolean positiveResult)

Parameters
positiveResult boolean

onDismiss

public void onDismiss (DialogInterface dialog)

Parameters
dialog DialogInterface

onSaveInstanceState

public void onSaveInstanceState (Bundle outState)

Parameters
outState Bundle

Protected methods

onBindDialogView

added in version 1.0.0
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.

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

onCreateDialogView

added in version 1.0.0
protected View onCreateDialogView (Context context)

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.

Parameters
context Context

Returns
View The content View for the dialog.

onPrepareDialogBuilder

added in version 1.0.0
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 AlertDialog.Builder.create() or AlertDialog.Builder.show().

Parameters
builder AlertDialog.Builder