获取单选按钮的排列在Android的一个RadioGroup中 [英] Get the array of RadioButtons in a RadioGroup in Android

查看:218
本文介绍了获取单选按钮的排列在Android的一个RadioGroup中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么办法获得单选数组的形式(或集合)在Android RadioGroup中的?我想个别的收听者添加到单选按钮,但我不认为遍历其中的任何明显的方法。

Is there any way of getting an array (or a collection) of the RadioButtons 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");

这篇关于获取单选按钮的排列在Android的一个RadioGroup中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆