Issue
why I can not check the same radiobutton after I uncheck it programmatically, when I click next button, unless I check another radiobutton.
This is the code that unchecks radiobuttons:
if(q.trim() != null || q.trim() != ""){
questionView.setText(q);
r1.setChecked(false);
r2.setChecked(false);
r3.setChecked(false);
r1.clearFocus();
r2.clearFocus();
r3.clearFocus();
r1.setText(varNames.get("ra0"));
r2.setText(varNames.get("ra1"));
r3.setText(varNames.get("ra2"));
}
And this is where I try to check it:
public void questionClicked(View view) {
boolean checked = ((RadioButton) view).isChecked();
switch(view.getId()) {
case R.id.firstQuestion:
if(!checked) {
r1.setChecked(true);
}
getAnswer(R.id.firstQuestion);
break;
case R.id.secondQuestion:
if(!checked) {
r2.setChecked(true);
}
getAnswer(R.id.secondQuestion);
break;
case R.id.thirdQuestion:
if(!checked) {
r3.setChecked(true);
}
getAnswer(R.id.thirdQuestion);
break;
}
}
Solution
I think you should make a method of clearing checked radio button. And call it everytime you click "next" button. Here is an example:
private void clearcheck(){
if(q.trim() != null || q.trim() != ""){
questionView.setText(q);
r1.setChecked(false);
r2.setChecked(false);
r3.setChecked(false);
r1.clearFocus();
r2.clearFocus();
r3.clearFocus();
r1.setText(varNames.get("ra0"));
r2.setText(varNames.get("ra1"));
r3.setText(varNames.get("ra2"));
}
}
Call it like clearcheck(); in onclick of your next button.
Answered By - Hasan Saykın
Answer Checked By - Senaida (JavaFixing Volunteer)