I am developing a PreferenceActivity where I can add CheckBoxPreference instances according to some dynamic content. I also maintain a count of the checked preferences in the activity. Everything is good when I load the application for the first time. But when I select some 2-3 check boxes and deploy the application code again on emulator, the previously selected check boxes just remain checked when I come back to same activity. The same happens when I move to and from some activities within the same application!
To prevent this, every time when I create an instance of CheckBoxPreference, I explicitly call .setChecked(false)
!!! But still those previously checked preferences remain checked only!
I can't understand the behavior! Does it bring those values checked from cache! But I explicitly call .setChecked(false)
, what about that then?
Thank you very much,
Ketan
EDIT : Here is my code:
String content = null;
for (String title : titles) {
checkBoxPref = new CheckBoxPreference(this);
checkBoxPref.setKey(title);
checkBoxPref.setTitle(title);
<b>checkBoxPref.setDefaultValue(Boolean.FALSE); //Line # 1 set default to false
checkBoxPref.setChecked(false);//Line # 2 set checked = false </b>
content = config.getString(title, "Yet to define!");
if (content.length() > 30) {
content = content.substring(0, 30);
}
checkBoxPref.setSummary(content);
checkBoxPref.setOnPreferenceChangeListener(new MyCheckBoxChangeListener());
checkBoxPreferenceList.add(checkBoxPref);
inlinePrefCat.addPreference(checkBoxPref);
}
This code is executed everytime I app comes back to this activity! But still had I checked 2-3 checkboxes before leaving this activity, they will remain in the same state when app comes back to this! Please have a look at the code, I am already setting setChecked(false) explicitly, but still can't get them unchecked!
Please suggest some solution! I am stuck!