Skip to content Skip to sidebar Skip to footer

Checkboxpreference - Onsharedpreferencechanged Method Not Getting Called

I have a couple of CheckBoxPreferences set up, my preference class extends PreferenceActivity and implements OnSharedPreferenceChangeListener This is what I'm using to respond to p

Solution 1:

Here is the soln if you want to do something on all the preferences:

Create a class member:

SharedPreferences settings;

in your onCreate method:

settings = getSharedPreferences(<your_pref_name>, 0);
settings.registerOnSharedPreferenceChangeListener(newSharedPreferences.OnSharedPreferenceChangeListener() {
  @OverridepublicvoidonSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
    // Do whatever
  }
});

Solution 2:

checkBoxPreference = (CheckBoxPreference) this.findPreference("CheckBoxPref_KEY_HERE");

checkBoxPreference.setOnPreferenceChangeListener(newOnPreferenceChangeListener() {
    @OverridepublicbooleanonPreferenceChange(Preference preference, Object newValue) {
            // do your work herereturntrue;
        }
    });

Post a Comment for "Checkboxpreference - Onsharedpreferencechanged Method Not Getting Called"