I'm trying to programmatically uncheck all the CheckBoxPreference
children of a PreferenceScreen
in my app. How can I do that?
views:
45answers:
2
+1
A:
Cannot test it right now... but I'd try something like this:
final ListAdapter adapter = getPreferenceScreen().getRootAdapter();
for (int idx = 0; idx < adapter.getCount(); idx++) {
Object object = adapter.getItem(idx);
if(object instanceof CheckBoxPreference){
((CheckBoxPreference)object).setChecked(false);
}
}
Cristian
2010-05-11 16:34:47
+1
A:
Found a simpler way - sufficient for my use case - which is to clear the preferences. This can be done by a static method provided a context is passed to it:
PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
JRL
2010-05-11 20:37:57