public class MultiSelectListPreference extends DialogPreference
Preference
that displays a list of entries as
a dialog.
This preference will store a set of strings into the SharedPreferences.
This set will contain one or more values from the
setEntryValues(CharSequence[])
array.
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
MultiSelectListPreference(Context context) |
MultiSelectListPreference(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[] |
getEntryValues()
Returns the array of values to be saved for the preference.
|
Set<String> |
getValues()
Retrieves the current 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 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 |
setValues(Set<String> values)
Sets the value of the key.
|
getDialog, getDialogIcon, getDialogLayoutResource, getDialogMessage, getDialogTitle, getNegativeButtonText, getPositiveButtonText, needInputMethod, onActivityDestroy, onBindDialogView, onClick, onClick, onCreateDialogView, onDismiss, onRestoreInstanceState, 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, 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, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toString
public MultiSelectListPreference(Context context, AttributeSet attrs)
public MultiSelectListPreference(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 setValues(Set<String> values)
getEntryValues()
.values
- The values to set for the key.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)