检查Android中多个复选框 [英] Checking Multiple Checkboxes in Android
本文介绍了检查Android中多个复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CheckBox checkOne = (CheckBox) findViewById(R.id.checkOne);
checkOne.setSelected(true);
CheckBox checkTwo = (CheckBox) findViewById(R.id.checkTwo);
checkTwo.setSelected(true);
CheckBox checkThree = (CheckBox) findViewById(R.id.checkThree);
checkThree.setSelected(true);
我使用上述code检查或取消选中多个复选框。
I am using the above code to check or uncheck multiple check boxes.
我的问题是,有没有什么办法,我可以立刻得到所有复选框? (我不想使用数组)
例如,我的复选框处于的LinearLayout,这样我就可以得到所有的复选框,LinearLayout中的孩子?
推荐答案
如果父LinearLayout中包含的仅的复选框,你可以这样做:
If the parent LinearLayout contains only the checkboxes, you can do this:
//ll is the LinearLayout holding the children
for(int i = 0; i < ll.getChildCount(); i++) {
((CheckBox)ll.getChildAt(i)).setChecked(true);
}
如果你在的LinearLayout更多的意见,你可以添加一个检查是这样的:
if you have more views in the LinearLayout you could add a check like this:
for(int i = 0; i < ll.getChildCount(); i++) {
View v = ll.getChildAt(i);
if(v instanceof CheckBox) {
((CheckBox)v).setChecked(true);
}
}
这篇关于检查Android中多个复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文