作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有一个单选组,我不希望用户能够选择任何按钮,直到在我的应用程序中选择了一个特定的复选框。如果未选中该复选框,则会禁用 radio 组。我该怎么做。
最佳答案
真正的诀窍是遍历所有 subview (在本例中为:CheckBox
)并将其称为 setEnabled(boolean)
这样的事情应该可以解决问题:
//initialize the controls
final RadioGroup rg1 = (RadioGroup)findViewById(R.id.radioGroup1);
CheckBox ck1 = (CheckBox)findViewById(R.id.checkBox1);
//set setOnCheckedChangeListener()
ck1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton checkBox, boolean checked) {
//basically, since we will set enabled state to whatever state the checkbox is
//therefore, we will only have to setEnabled(checked)
for(int i = 0; i < rg1.getChildCount(); i++){
((RadioButton)rg1.getChildAt(i)).setEnabled(checked);
}
}
});
//set default to false
for(int i = 0; i < rg1.getChildCount(); i++){
((RadioButton)rg1.getChildAt(i)).setEnabled(false);
}
关于android - 如何在选中复选框之前禁用 RadioGroup,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9376966/
我是一名优秀的程序员,十分优秀!