MultiSelectListPreference
public class MultiSelectListPreference extends DialogPreference
| java.lang.Object | |||
| ↳ | androidx.preference.Preference | ||
| ↳ | androidx.preference.DialogPreference | ||
| ↳ | androidx.preference.MultiSelectListPreference |
A Preference that displays a list of entries as a dialog.
This preference saves a set of strings. This set will contain one or more mValues from the setEntryValues array.
name android:entries
name android:entryValues
Summary
Public constructors |
|---|
MultiSelectListPreference(@NonNull Context context) |
MultiSelectListPreference( |
MultiSelectListPreference( |
MultiSelectListPreference( |
Public methods |
|
|---|---|
int |
findIndexOfValue(String value)Returns the index of the given value (in the entry mValues array). |
CharSequence[] |
The list of entries to be shown in the list in subsequent dialogs. |
CharSequence[] |
Returns the array of mValues to be saved for the preference. |
Set<String> |
Retrieves the current values of the key. |
void |
setEntries(CharSequence[] entries)Sets the human-readable entries to be shown in the list. |
void |
setEntries(@ArrayRes 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(@ArrayRes int entryValuesResId) |
void |
Sets the values for the key. |
Protected methods |
|
|---|---|
boolean[] |
|
@Nullable Object |
onGetDefaultValue(@NonNull TypedArray a, int index)Called when a preference is being inflated and the default value attribute needs to be read. |
void |
onRestoreInstanceState(@Nullable Parcelable state)Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by |
@Nullable Parcelable |
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. |
void |
onSetInitialValue(Object defaultValue)Implement this to set the initial value of the preference. |
Inherited Constants |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
MultiSelectListPreference
public MultiSelectListPreference(
@NonNull Context context,
@Nullable AttributeSet attrs
)
MultiSelectListPreference
public MultiSelectListPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
MultiSelectListPreference
public MultiSelectListPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
int defStyleRes
)
Public methods
findIndexOfValue
public int findIndexOfValue(String value)
Returns the index of the given value (in the entry mValues array).
| Parameters | |
|---|---|
String value |
The value whose index should be returned |
| Returns | |
|---|---|
int |
The index of the value, or -1 if not found |
getEntries
public CharSequence[] getEntries()
The list of entries to be shown in the list in subsequent dialogs.
| Returns | |
|---|---|
CharSequence[] |
The list as an array |
getEntryValues
public CharSequence[] getEntryValues()
Returns the array of mValues to be saved for the preference.
| Returns | |
|---|---|
CharSequence[] |
The array of mValues |
setEntries
public void setEntries(CharSequence[] entries)
Sets the human-readable entries to be shown in the list. This will be shown in subsequent dialogs.
Each entry must have a corresponding index in setEntryValues.
| Parameters | |
|---|---|
CharSequence[] entries |
The entries |
| See also | |
|---|---|
setEntryValues |
setEntries
public void setEntries(@ArrayRes int entriesResId)
| Parameters | |
|---|---|
@ArrayRes int entriesResId |
The entries array as a resource |
| See also | |
|---|---|
setEntries |
setEntryValues
public void setEntryValues(CharSequence[] entryValues)
The array to find the value to save for a preference when an entry from entries is selected. If a user clicks on the second item in entries, the second item in this array will be saved to the preference.
| Parameters | |
|---|---|
CharSequence[] entryValues |
The array to be used as mValues to save for the preference |
setEntryValues
public void setEntryValues(@ArrayRes int entryValuesResId)
| Parameters | |
|---|---|
@ArrayRes int entryValuesResId |
The entry mValues array as a resource |
| See also | |
|---|---|
setEntryValues |
Protected methods
onGetDefaultValue
protected @Nullable Object onGetDefaultValue(@NonNull TypedArray a, int index)
Called when a preference is being inflated and the default value attribute needs to be read. Since different preference types have different value types, the subclass should get and return the default value which will be its value type.
For example, if the value type is String, the body of the method would proxy to getString.
| Parameters | |
|---|---|
@NonNull TypedArray a |
The set of attributes |
int index |
The index of the default value attribute |
onRestoreInstanceState
protected void onRestoreInstanceState(@Nullable 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 state.
| Parameters | |
|---|---|
@Nullable Parcelable state |
The saved state that had previously been returned by |
| See also | |
|---|---|
onSaveInstanceState |
|
restoreHierarchyState |
onSaveInstanceState
protected @Nullable 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 | |
|---|---|
@Nullable Parcelable |
A Parcelable object containing the current dynamic state of this preference, or |
| See also | |
|---|---|
onRestoreInstanceState |
|
saveHierarchyState |
onSetInitialValue
protected void onSetInitialValue(Object defaultValue)
Implement this to set the initial value of the preference.
If you are persisting values to SharedPreferences or a PreferenceDataStore you should restore the saved value for the preference.
If you are not persisting values, or there is no value saved for the preference, you should set the value of the preference to defaultValue.
| Parameters | |
|---|---|
Object defaultValue |
The default value for the preference if set, otherwise |