[英]How to check is the button is selected in each radio group?
I have 3 radio groups, and I want to check is the button is selected in each radio group. 我有3个广播组,我想检查一下是否在每个广播组中都选择了按钮。
For example I want something like that 例如我想要这样的东西
if (in each radio group one button is selected){
do something
}
if ( one of RadioGroups have no selected button) {
Show something like Toast
}
Read the three group by name. 按名称阅读三组。 Then iterator other it.
然后迭代器其他它。 Check .checked using conditional statement.
使用条件语句检查.checked。
var radios = document.getElementsByTagName('input1');
var value;
for (var i = 0; i < radios.length; i++) {
if (radios[i].type === 'radio' && radios[i].checked) {
// get value, set checked flag or do whatever you need to
value = radios[i].value;
}
}
Suppose you have three radioButtons namely one two and three. 假设您有三个radioButton,即一二和三。 You could do like this.
你可以这样
if(one.isChecked() || two.isChecked() || three.isChecked()){
//do something
}else if(!one.isChecked() || !two.isChecked() || !three.isChecked()){
//do something
Toast.makeText(TourClass.this, "Passwords do not match",
Toast.LENGTH_LONG).show();
}
使用getCheckedRadioButtonId()
在RadioGroup
查找选中的RadioButton
。
for each RadioGroup you write this: 为每个RadioGroup编写以下代码:
if (radioGroup.getCheckedRadioButtonId() == -1)
{
// no radio buttons are checked
}
else
{
// one of the radio buttons is checked
}
and you can also check answers here How to check if a radiobutton is checked in a radiogroup in Android? 您还可以在此处查看答案如何检查Android中的单选按钮中是否选中了单选按钮?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.