public class YesNoPreference extends DialogPreference
YesNoPreference
is a preference to show a dialog with Yes and No
buttons.
This preference will store a boolean into the SharedPreferences.
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
YesNoPreference(Context context) |
YesNoPreference(Context context,
AttributeSet attrs) |
YesNoPreference(Context context,
AttributeSet attrs,
int defStyleAttr) |
YesNoPreference(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes) |
Modifier and Type | Method and Description |
---|---|
boolean |
getValue()
Gets the value of this preference.
|
protected void |
onDialogClosed(boolean positiveResult)
Called when the dialog is dismissed and should be used to save data to
the
SharedPreferences . |
protected Object |
onGetDefaultValue(TypedArray a,
int index)
Called when a Preference is being inflated and the default value
attribute needs to be read.
|
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.
|
protected void |
onSetInitialValue(boolean restorePersistedValue,
Object defaultValue)
Implement this to set the initial value of the Preference.
|
void |
setValue(boolean value)
Sets the value of this preference, and saves it to the persistent store
if required.
|
boolean |
shouldDisableDependents()
Checks whether this preference's dependents should currently be
disabled.
|
getDialog, getDialogIcon, getDialogLayoutResource, getDialogMessage, getDialogTitle, getNegativeButtonText, getPositiveButtonText, needInputMethod, onActivityDestroy, onBindDialogView, onClick, onClick, onCreateDialogView, onDismiss, onPrepareDialogBuilder, setDialogIcon, setDialogIcon, setDialogLayoutResource, setDialogMessage, setDialogMessage, setDialogTitle, setDialogTitle, setNegativeButtonText, setNegativeButtonText, setPositiveButtonText, setPositiveButtonText, showDialog
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, onKey, onParentChanged, onPrepareForRemoval, peekExtras, performClick, 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, shouldPersist, toString
public YesNoPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
public YesNoPreference(Context context, AttributeSet attrs, int defStyleAttr)
public YesNoPreference(Context context, AttributeSet attrs)
public YesNoPreference(Context context)
protected void onDialogClosed(boolean positiveResult)
DialogPreference
SharedPreferences
.onDialogClosed
in class DialogPreference
positiveResult
- Whether the positive button was clicked (true), or
the negative button was clicked or the dialog was canceled (false).public void setValue(boolean value)
value
- The value of the preference.public boolean getValue()
protected Object onGetDefaultValue(TypedArray a, int index)
Preference
For example, if the value type is String, the body of the method would
proxy to TypedArray.getString(int)
.
onGetDefaultValue
in class Preference
a
- The set of attributes.index
- The index of the default value attribute.protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue)
Preference
If restorePersistedValue is true, you should restore the
Preference value from the SharedPreferences
. If
restorePersistedValue is false, you should set the Preference
value to defaultValue that is given (and possibly store to SharedPreferences
if Preference.shouldPersist()
is true).
This may not always be called. One example is if it should not persist but there is no default value given.
onSetInitialValue
in class Preference
restorePersistedValue
- True to restore the persisted value;
false to use the given defaultValue.defaultValue
- The default value for this Preference. Only use this
if restorePersistedValue is false.public boolean shouldDisableDependents()
Preference
shouldDisableDependents
in class Preference
protected Parcelable onSaveInstanceState()
Preference
onSaveInstanceState
in class DialogPreference
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 DialogPreference
state
- The saved state that had previously been returned by
Preference.onSaveInstanceState()
.Preference.onSaveInstanceState()
,
Preference.restoreHierarchyState(android.os.Bundle)