Preferencescreen Android:summary Update !
In my android application I have a PreferenceScreen parent that has 3 CheckBoxPreferences as children. When I click the parent preferenceScreen, and the 3 checkboxes are displayed,
Solution 1:
Use
Parent.setSummary("string depending on the selection");
((BaseAdapter)getPreferenceScreen().getRootAdapter()).notifyDataSetChanged();
works like a charm and can be used regardless the place you change the summary.
Solution 2:
This is the correct way
Preference pref = findPreference(getString(R.string.key_of_pref));
PreferenceScreen parent = (PreferenceScreen) sf.findPreference(getString(R.string.key_of_preference_screen));
pref.setOnPreferenceChangeListener(newPreference.OnPreferenceChangeListener() {
@OverridepublicbooleanonPreferenceChange(Preference preference, Object newValue) {
boolean newValueBool = (Boolean) newValue;
parent.setSummary(newValueBool ? "Summary is true" : "Summary is false");
((BaseAdapter) getPreferenceScreen().getRootAdapter()).notifyDataSetChanged();
// true to update the state of the Preference with the new value// in case you want to disallow the change return falsereturntrue;
}
});
Solution 3:
I discovered that it seems to work by following up setSummary()
with getListView().invalidate()
Solution 4:
You can use BaseAdapter.notifyDataSetChanged()
on the parent PreferenceScreen
to update the UI
. See here for example code: Update existing Preference-item in a PreferenceActivity upon returning from a (sub)PreferenceScreen
Solution 5:
If you're using support preference than go for:
findPreference("your_preference").setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object o) {
getListView().getAdapter().notifyDataSetChanged();
return true;
}
});
Post a Comment for "Preferencescreen Android:summary Update !"