ListPreference's summary text is not updated automatically whenever there is change in selection
<p>Although it is being documented, by using <code>"%s"</code>, I can display selected value as summary, it doesn't work as expected.</p>

<p><a href="http://developer.android.com/reference/android/preference/ListPreference.html#getSummary%28%29" rel="nofollow">http://developer.android.com/reference/android/preference/ListPreference.html#getSummary%28%29</a></p>

<p>I am having the following <code>preferences.xml</code></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;PreferenceCategory
        android:title="@string/preference_xxx_category"&gt;
        &lt;CheckBoxPreference
            android:title="@string/preference_xxx_mode_title"
            android:defaultValue="false"
            android:summary="@string/preference_xxx_mode_summary"
            android:key="xxxModePreference" /&gt;
    &lt;/PreferenceCategory&gt;

    &lt;PreferenceCategory
        android:title="@string/preference_yyy_category"&gt;
        &lt;ListPreference
           android:title="@string/preference_yyy_mode_title"
           android:defaultValue="0"
           android:entries="@array/yyy"
           android:entryValues="@array/yyy_values"
           android:summary="%s"
           android:key="yyyModePreference" /&gt;         
    &lt;/PreferenceCategory&gt;

&lt;/PreferenceScreen&gt;
</code></pre>

<p>and here is my <code>arrays.xml</code></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;resources&gt;
    &lt;string-array name="yyy"&gt;
        &lt;item&gt;Display value 0&lt;/item&gt;
        &lt;item&gt;Display value 1&lt;/item&gt;
    &lt;/string-array&gt;

    &lt;string-array name="yyy_values"&gt;
        &lt;item&gt;0&lt;/item&gt;
        &lt;item&gt;1&lt;/item&gt;
    &lt;/string-array&gt;    
&lt;/resources&gt;
</code></pre>

<p>What I expecting by having the following Java code to build a complete preference activity, with a check box and a list preference, the summary text of list preference can be updated automatically, whenever I perform selection. The summary text will toggle in between <strong>Display value 0</strong> and <strong>Display value 1</strong>.</p>

<pre><code>public class Preferences extends PreferenceActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
    }
}
</code></pre>

<p>However, I realize the summary text for list preference will not update automatically. Only when I perform tick/ untick on check box, only the whole activity will be invalidate and summary text for list preference will ONLY be updated.</p>

<p>Hence, I have to revise my code as follow, which looks more <strong>cumbersome</strong>.</p>

<pre><code>public class Preferences extends PreferenceActivity implements OnSharedPreferenceChangeListener {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.preferences);
        PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
    }

    @Override
    public void onResume() {
        super.onResume();

        // Cumbersome way to make sure list preference's summary text is being updated.
        final String key = "yyyModePreference";
        ListPreference listPreference = (ListPreference)findPreference(key);
        final String value = PreferenceManager.getDefaultSharedPreferences(this).getString(key, key);
        final int index = listPreference.findIndexOfValue(value);
        if (index &gt;= 0) {
            final String summary = (String)listPreference.getEntries()[index];         
            listPreference.setSummary(summary);
        }
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences options, String key) {
        // Cumbersome way to make sure list preference's summary text is being updated.
        if (key.equals("yyyModePreference")) {
            ListPreference listPreference = (ListPreference)findPreference(key);
            final String value = options.getString(key, key);
            final int index = listPreference.findIndexOfValue(value);            
            if (index &gt;= 0) {
                final String summary = (String)listPreference.getEntries()[index];         
                listPreference.setSummary(summary);
            }
        }
    }
}
</code></pre>

<p>Is this a correct way? Is there any simplified way, to ensure ListPreference's summary text is always updated automatically whenever there is change in selection.</p>
