06 MultiChoiceListPreference - michael-rapp/AndroidMaterialPreferences GitHub Wiki
The preference MultiChoiceListPreference
is very similar to the preference ListPreference
, which has been discussed in the previous section. It also provides a list of items in its dialog, but instead of allowing to choose only one item, multiple items can be selected at once. The values, which can be selected by the preference, as well as the corresponding entries, which are shown within the preference's list, can be specified as arrays by either using setter methods or XML attributes. The values of the currently selected items are persisted as a set of strings in the shared preferences.
6.1 Getter and setter methods
The following table shows the getter and setter methods, which are provided in order to specify the properties of a MultiChoiceListPreference
programmatically. Because the class is extended from the class DialogPreference
, the methods of this class can also be used.
Getter and setter methods | Description | Default value | Restrictions |
---|---|---|---|
getValues():Set setValues(Set):void addValue(String):void removeValue(String):void addAllValues(Collection):void removeAllValues(Collection):void |
Returns or sets the currently persisted values of the preference or adds or removes specific values. If the values are changed, the changes are instantly persisted. | null |
none |
getDialogItemColor():int setDialogItemColor(int):void |
Returns or sets the color of the items of the preference's dialog. If the color is -1, the color ?android:attr/textColorPrimary is used. |
-1 |
none |
getEntries():CharSequence[] setEntries(CharSequence[]):void setEntries(int):void |
Returns or sets the entries, which are shown in the preference's list. | [] |
The array may not be null. If the array is specified as a resource ID, the ID must correspond to a valid array resource. |
getEntryValues():CharSequence[] setEntryValues(CharSequence[]):void setEntryValues(int):void |
Returns or sets the values, which correspond to the entries, which are shown in the preference's list. | [] |
The array may not be null. If the array is specified as a resource ID, the ID must correspond to a valid array resource. |
getSelectedEntries():CharSequence[] |
Returns the entries, which correspond to the currently selected values. | null |
none |
6.2 XML attributes
As an alternative to using the setter methods, which have been discussed in the previous section, XML attributes can be used to specify the properties of a MultiChoiceListPreference
in a XML resouce. The following attributes are available.
XML attribute | Description | Format |
---|---|---|
android:defaultValue |
A string array which contains the values, which should be selected by default. | reference |
custom:dialogItemColor |
The color of the items of the preference's dialog. | color |
android:entries |
The entries, which are shown in the preference's list. | reference |
android:entryValues |
The values, which correspond to the entries, which are shown in the preference's list. | reference |