I have a PreferenceScreen containing only CheckBoxPreferences (categories for selection). I need to check / uncheck all the checkboxes. I have the following code that does the job, but there is one problem: the flags on the screen are not updated - I will need to call some invalid ones in the view or something like that.
Here is my real code:
private void checkAll() { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = settings.edit(); @SuppressWarnings("unchecked") Map<String, Boolean> categories = (Map<String, Boolean>) settings.getAll(); for(String s : categories.keySet()) { editor.putBoolean(s, true); } editor.commit(); } private void uncheckAll() { SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor editor = settings.edit(); @SuppressWarnings("unchecked") Map<String, Boolean> categories = (Map<String, Boolean>) settings.getAll(); for(String s : categories.keySet()) { editor.putBoolean(s, false); } editor.commit(); this.restart(); }
This code works fine, but I need to update the view to see the imediatelly result (not only after closing and restarting the settings activity).
Thanks everyone for any advice!
source share