Search code examples
androidandroid-resourcesandroid-preferences

Is it possible to write string array literals in Android XML resource files?


For my PreferenceActivity, I am using the typical preferences.xml file.

The entryValues of a ListPreference is not something meant to be localized. Is it possible to define the entryValues attribute directly using some kind of array literal?

My first try below won't work, "pull, push" is considered a string:

<ListPreference
        android:key="server_reception_mode"
        android:title="@string/title_server_reception_mode_preference"
        android:entries="@array/entries_server_reception_mode_preference"
        android:entryValues="pull, push" />

Solution

  • Looking at the documentation for the entryValues attribute, no:

    Must be a reference to another resource [...]

    Of course, just because you have a string resource doesn't mean you have to localise it.