0

私は Android でアプリケーションを使用しており、リストの設定があります。問題は、値を取得すると、PreferenceManager.getDefaultSharedPreferences(context).getString(key, value)期待しているエントリ値ではなく、ローカライズされた文字列が返されることです。以前のバージョンでは動作していました。それは正しい行動ですか?その場合、エントリ値を取得するにはどうすればよいですか? 説明するコードを次に示します。

前もって感謝します。

Preferences.xml:

<ListPreference
android:id="@+id/protocol"
android:key="protocol"
android:title="@string/protocol"
android:dialogTitle="@string/change_protocol"
android:defaultValue="default"
android:entries="@array/protocol_entries"
android:entryValues="@array/protocol_entry_values" />

配列.xml

<string-array
    name="protocol_entry_values">
    <item>default</item>
    <item>protocol_1</item>
    <item>protocol_2</item>
    <item></item>
</string-array>
<string-array
    name="protocol_entries">
    <item>@string/label_default_protocol</item>
    <item>@string/label_protocol_1</item>
    <item>@string/label_protocol_2</item>
    <item>@string/label_other</item>
</string-array>

文字列.xml

<string name="label_default_protocol">Default protocol</string>
<string name="label_protocol_1">First protocol</string>
<string name="label_protocol_2">Second Protocol</string>
<string name="label_other">Other</string>
4

1 に答える 1

0

<string-array name="protocol_entry_values">ローカライズされた形式でさまざまなバージョンのデータがあるようです。値の定義は 1 つだけにする必要があります。はprotocol_entriesローカライズする必要があります。

于 2012-10-23T18:46:20.780 に答える