由网友(逗神无敌!)分享简介:有什么办法获得单选数组的形式(或集合)在Android RadioGroup中的?我想个别的收听者添加到单选按钮,但我不认为遍历其中的任何明显的方法。Is there any way of getting an array (or a collection) of the RadioButtons in an An...
有什么办法获得单选
数组的形式(或集合)在Android RadioGroup中
的?我想个别的收听者添加到单选按钮,但我不认为遍历其中的任何明显的方法。
Is there any way of getting an array (or a collection) of the RadioButton
s in an Android RadioGroup
? I would like to add individual listeners to radio buttons but I don't see any obvious way of iterating over them.
推荐答案
这应该做的伎俩:
int count = radioGroup.getChildCount();
ArrayList<RadioButton> listOfRadioButtons = new ArrayList<RadioButton>();
for (int i=0;i<count;i++) {
View o = radioGroup.getChildAt(i);
if (o instanceof RadioButton) {
listOfRadioButtons.add((RadioButton)o);
}
}
Log.d(TAG,"you have "+listOfRadioButtons.size()+" radio buttons");
相关推荐
最新文章