public abstract class DialogPreference extends Preference implements DialogInterface.OnClickListener, DialogInterface.OnDismissListener, PreferenceManager.OnActivityDestroyListener
Preference
objects that are
dialog-based. These preferences will, when clicked, open a dialog showing the
actual preference controls.Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
DialogPreference(Context context,
AttributeSet attrs) |
DialogPreference(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
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.
|
protected boolean |
needInputMethod()
Returns whether the preference needs to display a soft input method when the dialog
is displayed.
|
void |
onActivityDestroy()
See Activity's onDestroy.
|
protected void |
onBindDialogView(View view)
Binds views in the content View of the dialog to data.
|
protected void |
onClick()
Processes a click on the preference.
|
void |
onClick(DialogInterface dialog,
int which)
This method will be invoked when a button in the dialog is clicked.
|
protected View |
onCreateDialogView()
Creates the content view for the dialog (if a custom content view is
required).
|
protected void |
onDialogClosed(boolean positiveResult)
Called when the dialog is dismissed and should be used to save data to
the
SharedPreferences . |
void |
onDismiss(DialogInterface dialog)
This method will be invoked when the dialog is dismissed.
|
protected void |
onPrepareDialogBuilder(AlertDialog.Builder builder)
Prepares the dialog builder to be shown when the preference is clicked.
|
protected void |
onRestoreInstanceState(Parcelable state)
Hook allowing a Preference to re-apply a representation of its internal
state that had previously been generated by
Preference.onSaveInstanceState() . |
protected 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 |
setDialogIcon(Drawable dialogIcon)
Sets the icon of the dialog.
|
void |
setDialogIcon(int dialogIconRes)
Sets the icon (resource ID) 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(CharSequence dialogTitle)
Sets the title of the dialog.
|
void |
setDialogTitle(int dialogTitleResId) |
void |
setNegativeButtonText(CharSequence negativeButtonText)
Sets the text of the negative button of the dialog.
|
void |
setNegativeButtonText(int negativeButtonTextResId) |
void |
setPositiveButtonText(CharSequence positiveButtonText)
Sets the text of the positive button of the dialog.
|
void |
setPositiveButtonText(int positiveButtonTextResId) |
protected void |
showDialog(Bundle state)
Shows the dialog associated with this Preference.
|
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getEditor, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPersistedStringSet, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getTitleRes, getView, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onGetDefaultValue, onKey, onPrepareForRemoval, onSetInitialValue, peekExtras, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toString
public DialogPreference(Context context, AttributeSet attrs, int defStyle)
public DialogPreference(Context context, AttributeSet attrs)
public void setDialogTitle(CharSequence dialogTitle)
dialogTitle
- The title.public void setDialogTitle(int dialogTitleResId)
dialogTitleResId
- The dialog title as a resource.setDialogTitle(CharSequence)
public CharSequence getDialogTitle()
public void setDialogMessage(CharSequence dialogMessage)
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.
dialogMessage
- The message.public void setDialogMessage(int dialogMessageResId)
dialogMessageResId
- The dialog message as a resource.setDialogMessage(CharSequence)
public CharSequence getDialogMessage()
public void setDialogIcon(Drawable dialogIcon)
dialogIcon
- The icon, as a Drawable
.public void setDialogIcon(int dialogIconRes)
dialogIconRes
- The icon, as a resource ID.public Drawable getDialogIcon()
Drawable
.public void setPositiveButtonText(CharSequence positiveButtonText)
positiveButtonText
- The text of the positive button.public void setPositiveButtonText(int positiveButtonTextResId)
positiveButtonTextResId
- The positive button text as a resource.setPositiveButtonText(CharSequence)
public CharSequence getPositiveButtonText()
public void setNegativeButtonText(CharSequence negativeButtonText)
negativeButtonText
- The text of the negative button.public void setNegativeButtonText(int negativeButtonTextResId)
negativeButtonTextResId
- The negative button text as a resource.setNegativeButtonText(CharSequence)
public CharSequence getNegativeButtonText()
public void setDialogLayoutResource(int dialogLayoutResId)
View
to be shown
as the content View of subsequent dialogs.dialogLayoutResId
- The layout resource ID to be inflated.setDialogMessage(CharSequence)
public int getDialogLayoutResource()
protected void onPrepareDialogBuilder(AlertDialog.Builder builder)
Do not AlertDialog.Builder#create()
or
AlertDialog.Builder#show()
.
protected void onClick()
Preference
SharedPreferences
. However, the overridden method should
call Preference.callChangeListener(Object)
to make sure the client wants to
update the preference's state with the new value.onClick
in class Preference
protected void showDialog(Bundle state)
state
- Optional instance state to restore on the dialogprotected boolean needInputMethod()
protected View onCreateDialogView()
Preference.setLayoutResource(int)
protected void onBindDialogView(View view)
Make sure to call through to the superclass implementation.
view
- The content View of the dialog, if it is custom.public void onClick(DialogInterface dialog, int which)
DialogInterface.OnClickListener
onClick
in interface DialogInterface.OnClickListener
dialog
- The dialog that received the click.which
- The button that was clicked (e.g.
DialogInterface.BUTTON1
) or the position
of the item clicked.public void onDismiss(DialogInterface dialog)
DialogInterface.OnDismissListener
onDismiss
in interface DialogInterface.OnDismissListener
dialog
- The dialog that was dismissed will be passed into the
method.protected void onDialogClosed(boolean positiveResult)
SharedPreferences
.positiveResult
- Whether the positive button was clicked (true), or
the negative button was clicked or the dialog was canceled (false).public Dialog getDialog()
public void onActivityDestroy()
onActivityDestroy
in interface PreferenceManager.OnActivityDestroyListener
protected Parcelable onSaveInstanceState()
Preference
onSaveInstanceState
in class Preference
Preference.onRestoreInstanceState(android.os.Parcelable)
,
Preference.saveHierarchyState(android.os.Bundle)
protected void onRestoreInstanceState(Parcelable state)
Preference
Preference.onSaveInstanceState()
.
This function will never be called with a null state.onRestoreInstanceState
in class Preference
state
- The saved state that had previously been returned by
Preference.onSaveInstanceState()
.Preference.onSaveInstanceState()
,
Preference.restoreHierarchyState(android.os.Bundle)