使用教育Android应用程序。一个通过EditText
输入,单选按钮和CheckBox
提供答案。
我希望检查RadioGroup
,当没有点击RadioButton
时,它会提示学生并阻止提交。我成功EditText
但未成功RadioButton
。
public void checkEmptyButtons(View view){
RadioGroup rg = (RadioGroup) findViewById(R.id.myRg);
if (rg.getCheckedRadioButton()==-1{
// this is where I have a problem
//I don't even know how to search on the //dev.anderoid site
}
}
那个被困的地方。提前致谢
答案 0 :(得分:0)
使用getCheckedRadioButtonId()
代替getCheckedRadioButton()
。
if (rg.getCheckedRadioButtonId() == -1) {
//no radio buttons are checked
}
else {
//any one of the radio buttons is checked
}
答案 1 :(得分:0)
你需要radioGroup checked Change Listener:
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
//here you will get callback everytime radio button is checked along with id. You can have boolean checked here to know if any of your radio button is checked
}
});