Here's a bit of code that I wrote that scales nicely (and provides
correct summaries).
public class SettingsActivity extends PreferenceActivity implements
OnSharedPreferenceChangeListener {
private static final String tag = "SettingsActivity";
private SharedPreferences sharedPreferences;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.settings);
this.sharedPreferences = this.getPreferenceManager
().getSharedPreferences();
this.sharedPreferences.registerOnSharedPreferenceChangeListener
(this);
updateSummaries();
}
public void onSharedPreferenceChanged(SharedPreferences
sharedPreferences, String key) {
updateSummaries();
Log.i(tag, "Updated summaries.");
}
private void updateSummaries() {
Map<String, ?> map = this.sharedPreferences.getAll();
for(String key : map.keySet()) {
Preference pref = this.findPreference(key);
if(pref == null) continue;
if(pref instanceof CheckBoxPreference) continue;
pref.setSummary(this.sharedPreferences.getString(key,
key));
}
}
}
This should work good :)
Happy coding!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---