【发布时间】:2018-01-22 13:04:33
【问题描述】:
我想检查单选按钮是否被点击改变一些值
这是我的代码:
new DynamicViews().makeRadioButton(getApplicationContext(),radioGroup,"Ok");
new DynamicViews().makeRadioButton(getApplicationContext(),radioGroup,"Ok");
RadioButton radioButton =
new DynamicViews().makeRadioButtonforAnswer(getApplicationContext(),radioGroup,"This is the answer");
前两个收音机是在没有参考的情况下创建的,但最后一个是我的答案,所以我得到了一个参考来检查是否已检查。
这是我的问题: 我如何检查radioButton是否被勾选?
radioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
goToNextLevel = true;
}
});
到目前为止,这是我的方法,但它不能完美地工作,因为当用户选择 radioButton 并且之后会改变他们的选择时,goToNextLevel 的值不会改变,并且会以错误的方式设置为 true。
只要选中单选按钮,如何找出将 goToNextLevel 设置为 true,否则设置为 false。
【问题讨论】:
标签: android radio-button