There are ways to make this a more generic solution, if that suits your needs.
For example, if you want to generically have all list preferences show their choice as summary, you could have this for your onSharedPreferenceChanged
implementation:
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Preference pref = findPreference(key);
if (pref instanceof ListPreference) {
ListPreference listPref = (ListPreference) pref;
pref.setSummary(listPref.getEntry());
}
}
This is easily extensible to other preference classes.
And by using the getPreferenceCount
and getPreference
functionality in PreferenceScreen
and PreferenceCategory
, you could easily write a generic function to walk the preference tree setting the summaries of all preferences of the types you desire to their toString
representation