一个Android RadioGroup中的设置选择指数 [英] Set selected index of an Android RadioGroup

查看:594
本文介绍了一个Android RadioGroup中的设置选择指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法来设置一个RadioGroup中的机器人所选择的指标,而不是通过子循环单选按钮并选择检查单选按钮,选择指数?其他

Is there a way to set the selected index of a RadioGroup in android, other than looping through the child radiobuttons and selecting checking the radio button at the selected index?

注:我在运行时填充的单选按钮组

Note: I am populating the Radio Button Group at run time.

推荐答案

如果您的无线组在布局XML文件中定义的,每个按钮可以分配一个ID。然后你只需选中一个按钮,像这样

If your radio group is defined in a layout xml file, each button can be assigned an id. Then you just check a button like this

radioGroup.check(R.id.myButtonId);

如果您以编程方式创建的单选按钮组(我什至不知道你如何做到这一点?),你可能要考虑创建一个特殊的布局xml文件只是为单选组,以便您可以指定R.id *的ID的按钮。

If you created your radio group programmatically (I'm not even sure how you do this...), you might want to consider creating a special layout xml file just for the radio group so that you can assign R.id.* ids to the buttons.

请看看你,其实,希望通过指数来设置单选按钮组下面的回答,请参阅下面的答案。

Please see the answer below if you are, in fact, looking to set the radio button group by index, see the answer below.

这篇关于一个Android RadioGroup中的设置选择指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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