Try to do like this
switch (v.getId()) {
case R.id.cb1:
if (cb1.isChecked()) {
cb2.setChecked(false);
}else {
cb2.setChecked(true);
}
break;
题
I have question,
I have checkbox,that are cb1,cb2,cb3,cb4. I want, when i checked cb1 then cb2 will be disable and cb3,cb4 keep enable, after that i checked again cb3 then cb4 will be disable too.
The 1st step it worked well, but when i try to checked cb3, then cb4 wont be disable. there is my code
public void onCheckboxClicked(View v){
CheckBox cb1= (CheckBox)findViewById(R.id.cb1);
CheckBox cb2= (CheckBox)findViewById(R.id.cb2);
CheckBox cb3= (CheckBox)findViewById(R.id.cb3);
CheckBox cb4= (CheckBox)findViewById(R.id.cb4);
switch (v.getId()) {
case R.id.cb1:
if (cb1.isChecked()) {
cb2.setEnabled(false);
}else {
cb2.setEnabled(true);
}
break;
//......
please help me guys!!
Update Question:
what i mean, something like this,I have a 10 checkboxes, when I was checking one of them, then the number of checkboxes that can be checked turned into 5, then when one of these 5 checkbox is checked, then it will be reduced again to 2 checkbox where is enable to be checked, will be like that until there are no more checkboxes can be checked
解决方案
Try to do like this
switch (v.getId()) {
case R.id.cb1:
if (cb1.isChecked()) {
cb2.setChecked(false);
}else {
cb2.setChecked(true);
}
break;