Android: How Do I Enable/disable A Checkbox, Depending On A Radio Button Being Selected First
Basically I have a Radio Group with two radio buttons, one of them is labelled RUN and the other is labelled PASS. Just underneath this I also have a check-box labelled 'Pass Compl
Solution 1:
I've managed to answer my question with a little more research, may help others as well...
privatevoidinitialize() {
// TODO Auto-generated method stub
RadioGroup1 = (RadioGroup) findViewById(R.id.runandpass);
Radio1 = (RadioButton) findViewById(R.id.radiobuttonrun);
Radio2 = (RadioButton) findViewById(R.id.radiobuttonpass);
checkBoxcmpltpass = (CheckBox) findViewById(R.id.checkBoxcmpltpass);
RadioGroup1.setOnCheckedChangeListener(this);
}
publicvoidonCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stubswitch(checkedId){
case R.id.radiobuttonrun:
checkBoxcmpltpass.setEnabled(false);
break;
case R.id.radiobuttonpass:
checkBoxcmpltpass.setEnabled(true);
break;
}
}
Solution 2:
try this :
mRadioGroup1 = (RadioGroup) findViewById(R.id.runandpass);
mRadio1 = (RadioButton) findViewById(R.id.radiobuttonrun);
mRadio2 = (RadioButton) findViewById(R.id.radiobuttonpass);
mcheckBoxcmpltpass= (RadioButton) findViewById(R.id.checkBoxcmpltpass);
/*RadioGroup?OnCheckedChangeListener???*/
mRadioGroup1.setOnCheckedChangeListener(mChangeRadio);
}
private RadioGroup.OnCheckedChangeListenermChangeRadio=newRadioGroup.OnCheckedChangeListener()
{
@OverridepublicvoidonCheckedChanged(RadioGroup group, int checkedId)
{
// TODO Auto-generated method stubif(checkedId==mRadio1.getId())
{
/*?mRadio1*/
mcheckBoxcmpltpass.disabled=false;
}
elseif
(checkedId==mRadio2.getId())
{
/*?mRadio2*/
mcheckBoxcmpltpass.disabled=true;
}
}
};
Solution 3:
Solution 4:
You probably will want to add a listener to your checkbox, that will check for the selection and update the other views as needed.
captureGrp = (RadioGroup) findViewById(R.id.runandpass);
myRadio1 = (RadioButton) findViewById(R.drawable.radio1);
myRadio2 = (RadioButton) findViewById(R.drawable.radio2);
myRadio3 = (RadioButton) findViewById(R.drawable.radio3);
captureGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
publicvoidonCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.radio1) {
//disable and enable as needed
} elseif (checkedId == R.id.radio2) {
// disable as needed
} else {
// add as many as you need
}
}
Solution 5:
try this
finalCheckBoxcl_chk= (CheckBox) view.findViewById(R.id.cl_chk);
cl_chk.setEnabled(false);
This will help you out...
Post a Comment for "Android: How Do I Enable/disable A Checkbox, Depending On A Radio Button Being Selected First"