Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between entries and entry values in android listPreferences xml?

Here is my code:

How do they differ and which values get displayed on the dialog?

<ListPreference
    android:entryValues="@array/level"
    android:entries="@array/level"
    android:key="pref_numberOfChoices"
    android:persistent="true"
    android:summary="@string/level_description"
    android:title="@string/level_title"
    android:defaultValue="3"/>
like image 484
johnrao07 Avatar asked Oct 21 '15 11:10

johnrao07


2 Answers

You can check out the official doc about ListPreference.

android:entries The human-readable array to present as a list.

android:entryValues The array to find the value to save for a preference when an entry from entries is selected.

I other words: entries is what you see in the list and entryValues are the values you want to save when you do some action with the respective entry value.

like image 200
yugidroid Avatar answered Nov 16 '22 01:11

yugidroid


Basically it is key-value pair combination in which
android:entries - Act as Values
and
android:entryValues - Act as Key

For example : Usually we show list of Countries(android:entries) India, US, Nepal etc in spinner and when user select any of these country, programmer collect Id(android:entryValues ) associated with these countries to do operation.

For proper functioning count of key and value must be exactly same in list preference.
If android:entries are more and android:entryValues are less then if user select any entries OS wouldn't find any android:entryValues associated with that entry and app will crash :(

like image 25
Lokesh Tiwari Avatar answered Nov 15 '22 23:11

Lokesh Tiwari