0

I'm trying to learn how to do live wallpapers for android. I've got it working and now I want to add a couple preferences. So, I've created a preference activity and followed all the examples I could find.

I can capture ListBoxPreferences just fine, but the 'onSharedPreferenceChanged' method is never called when a checkbox has been changed.

Is there extra code that has to be added for capturing checkbox changes? Is there a best practices way of doing check boxes in preferences?

I've been banging my head against this issue for two days, any help would be GREATLY appreciated!

Thanks!

max
  • 2,346
  • 4
  • 26
  • 34

2 Answers2

0

Did you register to receive onSharedPreferenceChanged callbacks?

Add this to your main activity's onCreate method (and make sure to implement onSharedPreferenceChanged):

PreferenceManager.getDefaultSharedPreferences(getBaseContext()).registerOnSharedPreferenceChangeListener(this);
Josh Clemm
  • 2,966
  • 20
  • 21
  • Thanks for the suggestion. But I've done that already. Inside the onSharedPreferenceChanged method I'm doing this: System.out.println(prefs.getAll().toString()); which prints all the keys and values of the SharedPreference. However, the key for the checkbox is not listed. So for whatever reason the checkbox is not being listened to. Any Ideas? – max Nov 23 '10 at 21:08
  • Is there a chance you could post your preferences.xml file? – Josh Clemm Nov 23 '10 at 22:24
0

@Josh - Good answer.

I'd like to add for the sake of completeness is that you should set things up so you register for changes in your PreferenceActivity's onResume() method and unregister in the onPause() method.

The answer to this question has a good sample of code taken from on the the stock Android example programs.

Alternatively, you can also register listeners for each of the preferences in your activity's onCreate() and handle events on them separately .

Community
  • 1
  • 1
Jerry Brady
  • 3,050
  • 24
  • 30