RadioGroup

Panther0_0 2012-06-04 05:37:37
在程序中,怎么设置RadioGroup的初始值,调用哪个方法。(不是通过XML文件来设置的)
...全文
94 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Rayleigh 2012-06-05
  • 打赏
  • 举报
回复
code=Java]
RadioGroup rg = (RadioGroup)findViewById(R.id.RadioGroupId);[
[/code]
RadioGroupId就是你在xml文件里面设置的id.
大槐树2015 2012-06-05
  • 打赏
  • 举报
回复
不是用findViewById(int id)方法吗?
Panther0_0 2012-06-05
  • 打赏
  • 举报
回复
是这样的,是在xml中设置一组RadioGroup,我想在程序中动态的去初始化某个,这样如何处理。非常感谢
Panther0_0 2012-06-05
  • 打赏
  • 举报
回复
可能我描述的不清楚,其实就是想要用程序来控制选择的单选框。而不是通过点击

试用check(int)方法, 参数把所要选择的checkid传进去就可以了

谢谢两位
Rayleigh 2012-06-04
  • 打赏
  • 举报
回复
你如果是要用纯代码实例化一个RadioGroup,可以参考这个

final int sWrapContent = LinearLayout.LayoutParams.WRAP_CONTENT;
RadioGroup mRadioGroup1 = new RadioGroup(this);
mRadioGroup1.setOrientation(RadioGroup.VERTICAL);
RadioButton mRadio1 = new RadioButton(this);
mRadio1.setText("帅哥");
mRadio1.setId(1001);
mRadio1.setChecked(true);
RadioGroup.LayoutParams mRadioParams = new RadioGroup.LayoutParams(sWrapContent,sWrapContent);
mRadioGroup1.addView(mRadio1, mRadioParams);
Rayleigh 2012-06-04
  • 打赏
  • 举报
回复
调用其中某个RadioButton 的setChecked(boolean)方法就可以了。。。。

80,493

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧