我在共享首选项中创建列表,并调用onPreferenceChanged()方法时我想在某些情况下提取列表中项目的索引或整数值。在阵列从列表首选项获取整数或索引值
:我想建立XML数据如下
<string-array name="BackgroundChoices">
<item>Dark Background</item>
<item>Light Background</item>
</string-array>
<array name="BackgroundValues">
<item>1</item>
<item>0</item>
</array>
<string-array name="SpeedChoices">
<item>Slow</item>
<item>Medium</item>
<item>Fast</item>
</string-array>
<array name="SpeedValues">
<item>1</item>
<item>4</item>
<item>16</item>
</array>
在首xml文件
:
<PreferenceScreen android:key="Settings"
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="Settings">
<ListPreference
android:key="keyBackground"
android:entries="@array/BackgroundChoices"
android:summary="Select a light or dark background."
android:title="Light or Dark Background"
android:positiveButtonText="Okay"
android:entryValues="@array/BackgroundValues"/>
<ListPreference
android:key="keySpeed"
android:entries="@array/SpeedChoices"
android:summary="Select animation speed."
android:title="Speed" android:entryValues="@array/SpeedValues"/>
</PreferenceScreen>
所以我的XML不起作用。我知道如何使用字符串数组而不是数组来实现这个值。我可以抽出值字符串并从中得出我想要的值,但是我宁愿(如果可能)列出值为int,布尔值或枚举值的列表。习惯性的做法是什么?
在此先感谢,
周杰伦
那么这是一种讨厌。 – theblang 2014-02-13 17:32:46