public
abstract
class
PreferenceDialogFragmentCompat
extends DialogFragment
implements
DialogInterface.OnClickListener
java.lang.Object | |||
↳ | android.support.v4.app.Fragment | ||
↳ | android.support.v4.app.DialogFragment | ||
↳ | android.support.v7.preference.PreferenceDialogFragmentCompat |
Known Direct Subclasses |
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.
Constants | |
---|---|
String |
ARG_KEY
|
Inherited constants |
---|
From
class
android.support.v4.app.DialogFragment
|
Public constructors | |
---|---|
PreferenceDialogFragmentCompat()
|
Public methods | |
---|---|
DialogPreference
|
getPreference()
Get the preference that requested this dialog. |
void
|
onClick(DialogInterface dialog, int which)
This method will be invoked when a button in the dialog is clicked. |
void
|
onCreate(Bundle savedInstanceState)
Called to do initial creation of a fragment. |
Dialog
|
onCreateDialog(Bundle savedInstanceState)
Override to build your own custom Dialog container. |
abstract
void
|
onDialogClosed(boolean positiveResult)
|
void
|
onDismiss(DialogInterface dialog)
This method will be invoked when the dialog is dismissed. |
void
|
onSaveInstanceState(Bundle outState)
Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted. |
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 | |
---|---|
From
class
android.support.v4.app.DialogFragment
| |
From
class
android.support.v4.app.Fragment
| |
From
class
java.lang.Object
| |
From
interface
android.content.DialogInterface.OnCancelListener
| |
From
interface
android.content.DialogInterface.OnDismissListener
| |
From
interface
android.content.ComponentCallbacks
| |
From
interface
android.view.View.OnCreateContextMenuListener
| |
From
interface
android.content.DialogInterface.OnClickListener
|
PreferenceDialogFragmentCompat ()
DialogPreference getPreference ()
Get the preference that requested this dialog. Available after onCreate(Bundle)
has
been called on the PreferenceFragmentCompat
which launched this dialog.
Returns | |
---|---|
DialogPreference |
The DialogPreference associated with this
dialog.
|
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.
|
void onCreate (Bundle savedInstanceState)
Called to do initial creation of a fragment. This is called after
onAttach(Activity)
and before
onCreateView(LayoutInflater, ViewGroup, Bundle)
.
Note that this can be called while the fragment's activity is
still in the process of being created. As such, you can not rely
on things like the activity's content view hierarchy being initialized
at this point. If you want to do work once the activity itself is
created, see onActivityCreated(Bundle)
.
Any restored child fragments will be created before the base
Fragment.onCreate
method returns.
Parameters | |
---|---|
savedInstanceState |
Bundle :
If the fragment is being re-created from
a previous saved state, this is the state.
|
Dialog onCreateDialog (Bundle savedInstanceState)
Override to build your own custom Dialog container. This is typically
used to show an AlertDialog instead of a generic Dialog; when doing so,
onCreateView(LayoutInflater, ViewGroup, Bundle)
does not need
to be implemented since the AlertDialog takes care of its own content.
This method will be called after onCreate(Bundle)
and
before onCreateView(LayoutInflater, ViewGroup, Bundle)
. The
default implementation simply instantiates and returns a Dialog
class.
Note: DialogFragment own the Dialog.setOnCancelListener
and Dialog.setOnDismissListener
callbacks. You must not set them yourself.
To find out about these events, override onCancel(DialogInterface)
and onDismiss(DialogInterface)
.
Parameters | |
---|---|
savedInstanceState |
Bundle :
The last saved instance state of the Fragment,
or null if this is a freshly created Fragment. |
Returns | |
---|---|
Dialog |
Return a new Dialog instance to be displayed by the Fragment. |
void onDialogClosed (boolean positiveResult)
Parameters | |
---|---|
positiveResult |
boolean
|
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.
|
void onSaveInstanceState (Bundle outState)
Called to ask the fragment to save its current dynamic state, so it
can later be reconstructed in a new instance of its process is
restarted. If a new instance of the fragment later needs to be
created, the data you place in the Bundle here will be available
in the Bundle given to onCreate(Bundle)
,
onCreateView(LayoutInflater, ViewGroup, Bundle)
, and
onActivityCreated(Bundle)
.
This corresponds to Activity.onSaveInstanceState(Bundle)
and most of the discussion there
applies here as well. Note however: this method may be called
at any time before onDestroy()
. There are many situations
where a fragment may be mostly torn down (such as when placed on the
back stack with no UI showing), but its state will not be saved until
its owning activity actually needs to save its state.
Parameters | |
---|---|
outState |
Bundle :
Bundle in which to place your saved state.
|
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.
|
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. |
See also:
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.
Parameters | |
---|---|
builder |
AlertDialog.Builder
|