public class ListPreference extends DialogPreference
Preference
that displays a list of entries as
a dialog.
This preference will store a string into the SharedPreferences. This string will be the value
from the setEntryValues(CharSequence[])
array.
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
ListPreference(Context context) |
ListPreference(Context context,
AttributeSet attrs) |
Modifier and Type | Method and Description |
---|---|
int |
findIndexOfValue(String value)
Returns the index of the given value (in the entry values array).
|
CharSequence[] |
getEntries()
The list of entries to be shown in the list in subsequent dialogs.
|
CharSequence |
getEntry()
Returns the entry corresponding to the current value.
|
CharSequence[] |
getEntryValues()
Returns the array of values to be saved for the preference.
|
CharSequence |
getSummary()
Returns the summary of this ListPreference.
|
String |
getValue()
Returns the value of the key.
|
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 |
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.
|
protected void |
onSetInitialValue(boolean restoreValue,
Object defaultValue)
Implement this to set the initial value of the Preference.
|
void |
setEntries(CharSequence[] entries)
Sets the human-readable entries to be shown in the list.
|
void |
setEntries(int entriesResId) |
void |
setEntryValues(CharSequence[] entryValues)
The array to find the value to save for a preference when an entry from
entries is selected.
|
void |
setEntryValues(int entryValuesResId) |
void |
setSummary(CharSequence summary)
Sets the summary for this Preference with a CharSequence.
|
void |
setValue(String value)
Sets the value of the key.
|
void |
setValueIndex(int index)
Sets the value to the given index from the entry values.
|
getDialog, getDialogIcon, getDialogLayoutResource, getDialogMessage, getDialogTitle, getNegativeButtonText, getPositiveButtonText, needInputMethod, onActivityDestroy, onBindDialogView, onClick, onClick, onCreateDialogView, onDismiss, 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, getTitle, getTitleRes, getView, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onKey, onPrepareForRemoval, 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, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toString
public ListPreference(Context context, AttributeSet attrs)
public ListPreference(Context context)
public void setEntries(CharSequence[] entries)
Each entry must have a corresponding index in
setEntryValues(CharSequence[])
.
entries
- The entries.setEntryValues(CharSequence[])
public void setEntries(int entriesResId)
entriesResId
- The entries array as a resource.setEntries(CharSequence[])
public CharSequence[] getEntries()
public void setEntryValues(CharSequence[] entryValues)
entryValues
- The array to be used as values to save for the preference.public void setEntryValues(int entryValuesResId)
entryValuesResId
- The entry values array as a resource.setEntryValues(CharSequence[])
public CharSequence[] getEntryValues()
public void setValue(String value)
getEntryValues()
.value
- The value to set for the key.public CharSequence getSummary()
getSummary
in class Preference
Preference.setSummary(CharSequence)
public void setSummary(CharSequence summary)
setSummary
in class Preference
summary
- The summary for the preference.public void setValueIndex(int index)
index
- The index of the value to set.public String getValue()
getEntryValues()
.public CharSequence getEntry()
public int findIndexOfValue(String value)
value
- The value whose index should be returned.protected void onPrepareDialogBuilder(AlertDialog.Builder builder)
DialogPreference
Do not AlertDialog.Builder#create()
or
AlertDialog.Builder#show()
.
onPrepareDialogBuilder
in class DialogPreference
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).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 restoreValue, 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
restoreValue
- 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.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)