1

I created an android preference page and wanted to show the current option selected in the summary.

So I implemented the onSharedPreferenceChanged listener which is also called correctly. However, there is no screen change and the old option is shown.

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    // just update all
    ListPreference lp = (ListPreference) findPreference(PREF_DOWNLOAD_WEB);
    lp.setSummary(getString(R.string.pref_listDownloadWebSummary)  + ": %s");
}

Is this a known bug?

Gray
  • 112,334
  • 22
  • 281
  • 349
Gunnar Bernstein
  • 5,836
  • 1
  • 42
  • 64

1 Answers1

2

I noticed that the updated summary is shown when I set another prefs summary. So I set the summary to "dummy" first and then the real string. It works too.

public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    // just update all
    ListPreference lp = (ListPreference) findPreference(PREF_DOWNLOAD_WEB);
    lp.setSummary("dummy"); // required or will not update
    lp.setSummary(getString(R.string.pref_listDownloadWebSummary)  + ": %s");

}
Gunnar Bernstein
  • 5,836
  • 1
  • 42
  • 64
  • What versions of Android have you tried that on? %s doesn't seem to work on Android 2.3. (I didn't try exactly the same code, but something very similar.) – aij May 21 '14 at 21:53
  • This works fine on Android 2.3. Better if you post your code in a question. – Gunnar Bernstein May 29 '14 at 20:02
  • Well I'm using a Preference.OnPreferenceChangeListener instead, but I'm not sure it's really question worthy as it's pretty easy to just look up the string using findIndexOfValue. – aij May 29 '14 at 21:55