Note that there are some explanatory texts on larger screens.

plurals
  1. POListPreference summary not formatting
    primarykey
    data
    text
    <p>I have a ListPreference and I want to show the current entry in the summary. According to the <a href="http://developer.android.com/reference/android/preference/ListPreference.html#getSummary%28%29" rel="nofollow">docs for ListPreference.getSummary()</a>, I'm supposed to be able to do this by including <code>%s</code> in the summary string. Unfortunately, the activity just displays the <code>%s</code> in the summary.</p> <p>The XML is pretty standard:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;ListPreference android:key="displayMode" android:summary="@string/display_mode_summary" android:title="@string/display_mode" android:defaultValue="BOTH" android:entries="@array/displayModes" android:entryValues="@array/displayModeValues" /&gt; &lt;/PreferenceScreen&gt; </code></pre> <p>The value of the string <code>display_mode_summary</code> is just <code>%s</code>. (The value <code>"BOTH"</code> is present in the <code>displayModeValues</code> array.) If I subclass ListPreference like this:</p> <pre><code>public final class DisplayModePreference extends ListPreference { // ... @Override public CharSequence getSummary() { return String.format(super.getSummary().toString(), getEntry()); } } </code></pre> <p>then when the preferences activity starts, the current value is correctly interpolated into the summary. But when I click on the preference and select a different value from the dialog, when the dialog closes the summary still shows the now-old value. I need to close the preferences activity and restart it to see the change.</p> <p>I've tried this in several emulators at different API levels. What do I need to so that the displayed summary always reflects the current value?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload