如何使用android:entries数组中定义的字符串设置ListPreference的标题?

时间:2015-12-02 09:15:15

标签: android android-fragments

我希望在选择项目时更改ListPreference的标题。

例如,我希望ListPreference的标题可以显示字符串" Super"当我选择第一个项目时,在@string/RecordQuality_Super中定义。

目前,我可以放弃价值" 15"在我的代码中,我如何显示" Super" ?

final ListPreference my=(ListPreference) getPreferenceManager().findPreference("RecordQuality");
my.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
    public boolean onPreferenceChange(Preference preference,Object newValue) {

       my.setTitle(newValue.toString());

        return true;
    }
});

布局文件

<ListPreference
        android:key="RecordQuality"
        android:defaultValue="8"
        android:entries="@array/RecordQualityOption"
        android:entryValues="@array/RecordQualityOption_values"
        android:title="@string/RecordQualityTitle"
        android:summary="@string/RecordQualitySummary"
        android:layout="@layout/layout_customize_preference_item"
     />

字符串数组

 <string-array name="RecordQualityOption">
        <item>@string/RecordQuality_Super</item>
        <item>@string/RecordQuality_High</item>
        <item>@string/RecordQuality_Medium</item>
        <item>@string/RecordQuality_Low</item>
    </string-array>

    <string-array name="RecordQualityOption_values">
        <item>15</item>
        <item>8</item>
        <item>4</item>
        <item>2</item>
    </string-array>

翻译

 <string name="RecordQuality_Super">Super</string>
    <string name="RecordQuality_High">High</string>
    <string name="RecordQuality_Medium">Medium</string>
    <string name="RecordQuality_Low">Low</string>

0 个答案:

没有答案