johnrao07
johnrao07

Reputation: 6938

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"/>

Upvotes: 15

Views: 9332

Answers (2)

Lokesh Tiwari
Lokesh Tiwari

Reputation: 10586

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 :(

Upvotes: 7

yugidroid
yugidroid

Reputation: 6690

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.

Upvotes: 31

Related Questions