Skip to content
Michael Rapp edited this page Dec 29, 2017 · 1 revision

The library's class ListPreference provides an implementation, whose purpose is equal to the Android SDK's built-in preference ListPreference. It allows to select a value from a list, which is shown within the preference's dialog. Only one value can be selected at once and the dialog becomes closed as soon as the list's selection changes. 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.

5.1 Getter and setter methods

To specify the properties of a ListPreference programmatically, the following getter and setter method are provided. As the class is extended from the class DialogPreference, the methods of this base class can also be used.

Getter and setter methods Description Default value Restrictions
getValue():String setValue():void setValueIndex(int):void Returns or sets the currently persisted value of the preference. If a value is set, it is instantly persisted. null If the value is specified by its index, the index must be valid.
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.
getEntry():CharSequence Returns the entry, which corresponds to the currently selected value. null none

5.2 XML attributes

If the properties, which can be set by the using the setter methods, which have been discussed in the previous section, should be specified by using XML attributes, the following attributes are available.

XML attribute Description Format
android:defaultValue The preference's default value. string
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

Clone this wiki locally