I have over 100 different checkboxes in 6 activites and i would like to save the state of each, so that when i switch from one activity to another, it remains checked. Do i really have to create over 100 booleans to save each checkbox separately or is there an easier way to save and read out the states? I thought of using a loop but i cant really think of an intelligent way to do this. Would be great if anyone could help!
This is an example of one of my checkboxes: Its supposed to add a String to an ArrayList object when the box gets klicked and delete the String when the box gets unchecked. It works fine, but when i leave eg. Actvity1, go into Activity2 and come back to Acivity1 to uncheck one of my checkboxes, the string is added to my ArrayList a second time instead of beeing removed.
myBox1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (myBox1.isChecked() == true)
helperActivity.myStringArrayList.add("myString1");
else {
helperActivity.myStringArrayList.remove("myString1");}
}
});
One option would be to use Shared Preferences to save the checked state for each of your checkboxes.
The advantage of this scheme is that these settings will survive application restarts.