I added two check box in the on create method
checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
checkBox1.setOnCheckedChangeListener(this) ;
checkBox2.setOnCheckedChangeListener(this) ;
the main function of the check boxes that when ischeck() a picture will be added to the mainlayout and when uncheck the picture will be removed >> I used the code bellow, the first check box is working fine the second check box when I do check it shows the pics and then they I can remove them even with uncheck … where is the wrong in my code ??
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// TODO Auto-generated method stub
if(checkBox1.isChecked())
{
......
mapOverlays.add(custom);
}
else {
mapOverlays.remove(custom) ;
}
if (checkBox2.isChecked())
{
....
mapOverlays.add(custom2);
}
else
{
mapOverlays.remove(custom2) ;
}
}
}
You are handling second checkbox checking differently. May be the code should look like this?
Upd: if your code looks like in the current edit, then issue is the declaring
custom2variable in theifblock. You are deleting not added mapOverlay, but another one declared somewhere else.Just replace
by
Upd2: there is yet another issue with your
onCheckedChanged()method. Firstif-elseruns not only on checkBox1 check/uncheck but also on checkBox2 check/uncheck. Same for the secondif-else.Try to rewrite method:
or even better: