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

2

15

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"/>
Tripper answered 21/10, 2015 at 11:5 Comment(0)
L
31

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.

Lombardy answered 21/10, 2015 at 11:22 Comment(0)
T
7

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

Tritanopia answered 6/12, 2015 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.