Search code examples
androidstringlistpreference

How to show text and value on Listpreference list


I'm trying to show the Listpreference list with both assigned arrays. Arrays look something like this.

level_array

     <item name="level1">Level  1 -   Hi-Score: </item>
     <item name="level2">Level  2 -   Hi-Score: </item>

value_array

     <item name="level1">5</item>
     <item name="level2">10</item>

when I call the listpreference, I'd like it to show both strings combined. Is this possible?

IE would show list like this

LIST TITLE

Level 1 - Hiscore 5

Level 2 - Hiscore 10

etc.

Secondary question, I'm guessing the value_array values are changeable via code so I can store different values there later?

Thanks


Solution

  • use ListPreference, use something like this

    <ListPreference
        android:title="Weather"
        android:summary="You can simulate the weather"
        android:key="listPref"
        android:entries="@array/level_array"
        android:entryValues="@array/value_array" />
    

    Is you want change your xml, I think there won't be a problem