android.preference
public
abstract
class
android.preference.DialogPreference
The DialogPreference class is a base class for preferences that are
dialog-based. These preferences will, when clicked, open a dialog showing the
actual preference controls.
Known Direct Subclasses
Summary
XML Attributes
android:defaultValue,
android:dependency,
android:enabled,
android:key,
android:layout,
android:order,
android:persistent,
android:selectable,
android:shouldDisableView,
android:summary,
android:title,
android:widgetLayout
Attribute name |
Related methods |
|
android:defaultValue |
|
The default value for the preference, which will be set either if persistence
is off or persistence is on and the preference is not found in the persistent
storage. |
android:dependency |
|
The key of another Preference that this Preference will depend on. |
android:enabled |
|
Whether the Preference is enabled. |
android:key |
|
The key to store the Preference value. |
android:layout |
|
The layout for the Preference in a PreferenceActivity screen. |
android:order |
|
The order for the Preference (lower values are to be ordered first). |
android:persistent |
|
Whether the Preference stores its value to the shared preferences. |
android:selectable |
|
Whether the Preference is selectable. |
android:shouldDisableView |
|
Whether the view of this Preference should be disabled when
this Preference is disabled. |
android:summary |
|
The summary for the Preference in a PreferenceActivity screen. |
android:title |
|
The title for the Preference in a PreferenceActivity screen. |
android:widgetLayout |
|
The layout for the controllable widget portion of a Preference. |
Public Constructors
Public Methods
Protected Methods
callChangeListener,
compareTo,
findPreferenceInHierarchy,
getContext,
getDependency,
getEditor,
getIntent,
getKey,
getLayoutResource,
getOnPreferenceChangeListener,
getOnPreferenceClickListener,
getOrder,
getPersistedBoolean,
getPersistedFloat,
getPersistedInt,
getPersistedLong,
getPersistedString,
getPreferenceManager,
getSharedPreferences,
getShouldDisableView,
getSummary,
getTitle,
getView,
getWidgetLayoutResource,
hasKey,
isEnabled,
isPersistent,
isSelectable,
notifyChanged,
notifyDependencyChange,
notifyHierarchyChanged,
onAttachedToActivity,
onAttachedToHierarchy,
onBindView,
onClick,
onCreateView,
onDependencyChanged,
onGetDefaultValue,
onPrepareForRemoval,
onRestoreInstanceState,
onSaveInstanceState,
onSetInitialValue,
persistBoolean,
persistFloat,
persistInt,
persistLong,
persistString,
restoreHierarchyState,
saveHierarchyState,
setDefaultValue,
setDependency,
setEnabled,
setIntent,
setKey,
setLayoutResource,
setOnPreferenceChangeListener,
setOnPreferenceClickListener,
setOrder,
setPersistent,
setSelectable,
setShouldDisableView,
setSummary,
setSummary,
setTitle,
setTitle,
setWidgetLayoutResource,
shouldCommit,
shouldDisableDependents,
shouldPersist,
toString
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait
Details
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
Public Methods
public
Drawable
getDialogIcon()
Returns the icon to be shown on subsequent dialogs.
public
int
getDialogLayoutResource()
Returns the layout resource that is used as the content View for
subsequent dialogs.
public
CharSequence
getDialogMessage()
Returns the message to be shown on subsequent dialogs.
Returns the title to be shown on subsequent dialogs.
public
CharSequence
getNegativeButtonText()
Returns the text of the negative button to be shown on subsequent
dialogs.
Returns
- The text of the negative button.
public
CharSequence
getPositiveButtonText()
Returns the text of the positive button to be shown on subsequent
dialogs.
Returns
- The text of the positive button.
public
void
onClick(DialogInterface dialog, int which)
This method will be invoked when a button in the dialog is clicked.
This method will be invoked when the dialog is dismissed.
public
void
setDialogIcon(Drawable dialogIcon)
Sets the icon of the dialog. This will be shown on subsequent dialogs.
public
void
setDialogIcon(int dialogIconRes)
Sets the icon (resource ID) of the dialog. This will be shown on
subsequent dialogs.
Parameters
dialogIconRes
| The icon, as a resource ID.
|
public
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
| The layout resource ID to be inflated. |
public
void
setDialogMessage(int dialogMessageResId)
Parameters
dialogMessageResId
| The dialog message as a resource.
|
public
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
| The message.
|
public
void
setDialogTitle(CharSequence dialogTitle)
Sets the title of the dialog. This will be shown on subsequent dialogs.
public
void
setDialogTitle(int dialogTitleResId)
Parameters
dialogTitleResId
| The dialog title as a resource.
|
public
void
setNegativeButtonText(CharSequence negativeButtonText)
Sets the text of the negative button of the dialog. This will be shown on
subsequent dialogs.
Parameters
negativeButtonText
| The text of the negative button.
|
public
void
setNegativeButtonText(int negativeButtonTextResId)
Parameters
negativeButtonTextResId
| The negative button text as a resource.
|
public
void
setPositiveButtonText(int positiveButtonTextResId)
Parameters
positiveButtonTextResId
| The positive button text as a resource.
|
public
void
setPositiveButtonText(CharSequence positiveButtonText)
Sets the text of the positive button of the dialog. This will be shown on
subsequent dialogs.
Parameters
positiveButtonText
| The text of the positive button.
|
Protected Methods
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
| The content View of the dialog, if it is custom.
|
protected
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.
protected
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
- The content View for the dialog.
protected
void
onDialogClosed(boolean positiveResult)
Called when the dialog is dismissed and should be used to save data to
the
SharedPreferences.
Parameters
positiveResult
| Whether the positive button was clicked (true), or
the negative button was clicked or the dialog was canceled (false).
|
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 create() or
show().
protected
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 icicle.
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. This state should only contain information that is not persistent
or can be reconstructed later.
Returns
- Returns a Parcelable object containing the preference's current
dynamic state, or null if there is nothing interesting to save.
The default implementation returns null.
protected
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
| Optional instance state to restore on the dialog
|