views:

45

answers:

2

I'm trying to programmatically uncheck all the CheckBoxPreference children of a PreferenceScreen in my app. How can I do that?

+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
+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