When I'm trying to set summary when the users select a preference item, it normally saved. But when my app is restarted, the summary is gone.
Here is my code to set the summary for ListPreference
and EditTextPreference
:
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key){
Preference pref = findPreference(key);
// I feel the problem is happened here
if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref;
pref.setSummary(listPref.getEntry());
}
// Same problem here
if (pref instanceof EditTextPreference) {
EditTextPreference editText = (EditTextPreference) pref;
pref.setSummary(editText.getEntry().toString());
}
}
Is there something wrong?