public class MultiSelectListPreference extends AbstractMultiSelectListPreference
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.
DialogPreference.TargetFragment
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
MultiSelectListPreference(Context context) |
MultiSelectListPreference(Context context,
AttributeSet attrs) |
MultiSelectListPreference(Context context,
AttributeSet attrs,
int defStyleAttr) |
MultiSelectListPreference(Context context,
AttributeSet attrs,
int defStyleAttr,
int defStyleRes) |
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.
|
protected Set<String> |
getPersistedStringSet(Set<String> defaultReturnValue)
Attempts to get a persisted set of Strings from the
SharedPreferences . |
protected boolean[] |
getSelectedItems() |
Set<String> |
getValues()
Retrieves the current value of the key.
|
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 restoreValue,
Object defaultValue)
Implement this to set the initial value of the Preference.
|
protected boolean |
persistStringSet(Set<String> values)
Attempts to persist a set of Strings to the
SharedPreferences . |
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.
|
getDialogIcon, getDialogLayoutResource, getDialogMessage, getDialogTitle, getNegativeButtonText, getPositiveButtonText, onClick, setDialogIcon, setDialogIcon, setDialogLayoutResource, setDialogMessage, setDialogMessage, setDialogTitle, setDialogTitle, setNegativeButtonText, setNegativeButtonText, setPositiveButtonText, setPositiveButtonText
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, isVisible, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttached, onAttachedToHierarchy, onAttachedToHierarchy, onBindViewHolder, onDependencyChanged, onDetached, onInitializeAccessibilityNodeInfo, onParentChanged, onPrepareForRemoval, peekExtras, performClick, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setViewId, setVisible, setWidgetLayoutResource, shouldDisableDependents, shouldPersist, toString
public MultiSelectListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
public MultiSelectListPreference(Context context, AttributeSet attrs, int defStyleAttr)
public MultiSelectListPreference(Context context, AttributeSet attrs)
public MultiSelectListPreference(Context context)
protected boolean persistStringSet(Set<String> values)
SharedPreferences
.
This will check if this Preference is persistent, get an editor from
the PreferenceManager
, put in the strings, and check if we should
commit (and commit if so).
values
- The values to persist.Preference.getPersistedString(java.lang.String)
protected Set<String> getPersistedStringSet(Set<String> defaultReturnValue)
SharedPreferences
.
This will check if this Preference is persistent, get the SharedPreferences
from the PreferenceManager
, and get the value.
defaultReturnValue
- The default value to return if either the
Preference is not persistent or the Preference is not in the
shared preferences.persistStringSet(Set)
public void setEntries(CharSequence[] entries)
Each entry must have a corresponding index in
setEntryValues(CharSequence[])
.
entries
- The entries.setEntryValues(CharSequence[])
public void setEntries(@ArrayRes int entriesResId)
entriesResId
- The entries array as a resource.setEntries(CharSequence[])
public CharSequence[] getEntries()
getEntries
in class AbstractMultiSelectListPreference
public void setEntryValues(CharSequence[] entryValues)
entryValues
- The array to be used as values to save for the preference.public void setEntryValues(@ArrayRes int entryValuesResId)
entryValuesResId
- The entry values array as a resource.setEntryValues(CharSequence[])
public CharSequence[] getEntryValues()
getEntryValues
in class AbstractMultiSelectListPreference
public void setValues(Set<String> values)
getEntryValues()
.setValues
in class AbstractMultiSelectListPreference
values
- The values to set for the key.public Set<String> getValues()
getValues
in class AbstractMultiSelectListPreference
public int findIndexOfValue(String value)
value
- The value whose index should be returned.protected boolean[] getSelectedItems()
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 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)