Reputation: 45
Am still a learner in android, please am trying to do the following in android. I want my checkbox to show my other checkbox only after I have click the first checkbox, but if the first is unchecked the rest should be invisible. For example Class 1: checkbox, should only show Class 2:checkbox only when Class 1: checked has been selected and so on for the rest checkbox. Please find my code below. Am willing to accept answer immediately once it works
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch (buttonView.getId()) {
case R.id.chk_clas1:
//do stuff
if (chk_clas1.isChecked()) {
if(c1.equals("0")){adddate(txt_clas1);}
clas="1";
fdate=txt_clas1.getText().toString();
} else {
txt_clas1.setText("");
}
break;
case R.id.chk_clas2:
//do stuff
if (chk_clas2.isChecked()) {
if(c2.equals("0")) {adddate(txt_clas2);}
clas="2";
fdate=txt_clas2.getText().toString();
} else {
txt_clas2.setText("");
}
break;
case R.id.chk_clas3:
//do stuff
if (chk_clas3.isChecked()) {
if(c3.equals("0")){
adddate(txt_clas3);}
clas="3";
fdate=txt_clas3.getText().toString();
} else {
txt_clas3.setText("");
}
break;
case R.id.chk_clas4:
//do stuff
if (chk_clas4.isChecked()) {
if(c4.equals("0")){
adddate(txt_clas4);}
clas="4";
fdate=txt_clas4.getText().toString();
} else {
txt_clas4.setText("");
}
break;
case R.id.chk_clas5:
//do stuff
if (chk_clas5.isChecked()) {
if(c5.equals("0")){
adddate(txt_clas5);}
clas="5";
fdate=txt_clas5.getText().toString();
} else {
txt_clas5.setText("");
}
break;
case R.id.chk_clas6:
//do stuff
if (chk_clas6.isChecked()) {
if(c6.equals("0")){
adddate(txt_clas6);}
clas="6";
fdate=txt_clas6.getText().toString();
} else {
txt_clas6.setText("");
}
break;
case R.id.chk_service1:
//do stuff
if (chk_service1.isChecked()) {
if(s1.equals("0")){
adddate(txt_service1);}
sday="1";
sdate=txt_service1.getText().toString();
} else {
txt_service1.setText("");
}
break;
case R.id.chk_service2:
//do stuff
if (chk_service2.isChecked()) {
if(s2.equals("0")){
adddate(txt_service2);}
sday="2";
sdate=txt_service2.getText().toString();
} else {
txt_service2.setText("");
}
break;
case R.id.chk_service3:
//do stuff
if (chk_service3.isChecked()) {
if(s3.equals("0")){
adddate(txt_service3);}
sday="3";
sdate=txt_service3.getText().toString();
} else {
txt_service3.setText("");
}
break;
case R.id.chk_service4:
//do stuff
if (chk_service4.isChecked()) {
if(s4.equals("0")){
adddate(txt_service4);}
sday="4";
sdate=txt_service4.getText().toString();
} else {
txt_service4.setText("");
}
break;
Upvotes: 1
Views: 91
Reputation: 4346
This is not code, just an idea .. Something out of my head:
//Initially
chkBx2.setVisibility(View.INVISIBLE);
onCheckListener-> //just showing idea, not code
if(chkbx1.isChecked()){
chkBx2.setVisibility(View.VISIBLE)
}
Upvotes: 1