android listPreferences xml 中的条目和条目值有什么区别?

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

这是我的代码:

它们有何不同以及哪些值显示在对话框中?

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

你可以查看关于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.

我换句话说:entries 是您在列表中看到的内容,entryValues 是您在执行某些操作时要保存的值具有相应条目值的操作。

基本上就是键值对组合其中
android:entries - 作为值

android:entryValues - 充当密钥

例如: 通常我们在微调器中显示国家列表(android:entries)印度、美国、尼泊尔等 当用户select这些国家中的任何一个时,程序员收集与这些国家相关的Id(android:entryValues)进行操作。

为了正常运行列表首选项中的键和值的数量必须完全相同
如果 android:entries 多而 android:entryValues 少,那么如果用户 select 任何条目 OS 都找不到与该条目关联的任何 android:entryValues 并且应用程序将崩溃: (