您的位置:首页 > 移动开发 > Android开发

执行RadioGroup的check(Id)方法,会触发onCheckedChanged多次

2017-03-23 17:10 465 查看
在百度下找到解决方法,特此记录下,把RadioGroup下的所有子View(RadioButton)的Checked设置为true,经过测试发现,的确可以解决onCheckChanged的多次执行

方法一:

((RadioButton)mRgBottomTag.findViewById(R.id.rb_video)).setChecked(true);
((RadioButton)mRgBottomTag.findViewById(R.id.rb_Audio)).setChecked(true);
等等...


方法二:

for (int i = 0; i < mRgBottomTag.getChildCount(); ++i){
RadioButton rb = (RadioButton) mRgBottomTag.getChildAt(i);
rb.setChecked(true);
}


上面两种方法执行后,发现RadioGroup的Check(id)方法不起作用了,小菜鸟不知道怎么解决这个问题,但是又想让app一启动就选中某个RadioButton,小菜鸟的解决是去掉上面的方法

方法一:

((RadioButton)mRgBottomTag.findViewById(R.id.rb_video)).setChecked(true);


方法二:

for (int i = 0; i < mRgBottomTag.getChildCount(); ++i){
RadioButton rb = (RadioButton) mRgBottomTag.getChildAt(i);
if(rb.getId() == R.id.rb_video){
rb.setChecked(true);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  radio button android View
相关文章推荐