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

PreferenceDialogFragment

abstract class PreferenceDialogFragment : DialogFragment, OnClickListener
kotlin.Any
   ↳ 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

static String

Public constructors

Public methods

open DialogPreference!

Get the preference that requested this dialog.

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

open Unit
onCreate(savedInstanceState: Bundle!)

open Dialog
onCreateDialog(savedInstanceState: Bundle!)

abstract Unit
onDialogClosed(positiveResult: Boolean)

open Unit

open Unit
onSaveInstanceState(@NonNull outState: Bundle)

Protected methods

open Unit

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

open View!

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

open Unit

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

Constants

ARG_KEY

protected static val ARG_KEY: String

Deprecated: Use PreferenceDialogFragmentCompat instead

Value: "key"

Public constructors

<init>

PreferenceDialogFragment()

Deprecated: Use PreferenceDialogFragmentCompat instead

Public methods

getPreference

open fun getPreference(): DialogPreference!

Deprecated: Use PreferenceDialogFragmentCompat instead

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

Return
DialogPreference!: The DialogPreference associated with this dialog

onClick

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

Deprecated: Use PreferenceDialogFragmentCompat instead

onCreate

open fun onCreate(savedInstanceState: Bundle!): Unit

onCreateDialog

@NonNull open fun onCreateDialog(savedInstanceState: Bundle!): Dialog

onDialogClosed

abstract fun onDialogClosed(positiveResult: Boolean): Unit

Deprecated: Use PreferenceDialogFragmentCompat instead

onDismiss

open fun onDismiss(dialog: DialogInterface!): Unit

onSaveInstanceState

open fun onSaveInstanceState(@NonNull outState: Bundle): Unit

Protected methods

onBindDialogView

protected open fun onBindDialogView(view: View!): Unit

Deprecated: Use PreferenceDialogFragmentCompat instead

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

protected open fun onCreateDialogView(context: Context!): View!

Deprecated: Use PreferenceDialogFragmentCompat instead

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

onPrepareDialogBuilder

protected open fun onPrepareDialogBuilder(builder: Builder!): Unit

Deprecated: Use PreferenceDialogFragmentCompat instead

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().