Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListPreference does not display selected value

Tags:

android

In my setting activity, after selecting a ListPreference to order the result list in ascending or descending, the selected vale does not appear in the ListPreference. Here is my code for this list preference. I have also attached a screenshot for this problem. Please let me know what is the problem and what was my mistake.

<ListPreference
        android:title="@string/pref_calllog_sorting"
        android:key="@string/pref_calllog_sorting_descending"
        android:defaultValue="@string/pref_calllog_sorting_descending"
        android:entryValues="@array/pref_calllog_sorting_values"
        android:entries="@array/pref_calllog_sorting_options" />

Screenshot for ListPreference

like image 742
Thiha Zaw Avatar asked Aug 24 '26 17:08

Thiha Zaw


1 Answers

By putting special string %s into summary attribute, you tell Android to show the selected entry.

Your XML will then be

<ListPreference
        android:title="@string/pref_calllog_sorting"
        android:key="@string/pref_calllog_sorting_descending"
        android:defaultValue="@string/pref_calllog_sorting_descending"
        android:entryValues="@array/pref_calllog_sorting_values"
        android:entries="@array/pref_calllog_sorting_options"
        android:summary="%s"
        />
like image 105
Štěpán Avatar answered Aug 27 '26 07:08

Štěpán