在百度下找到解决方法,特此记录下,把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);
}
}
本文介绍了解决Android开发中RadioGroup组件多次触发onCheckChanged回调的问题。通过设置所有RadioButton初始状态为Checked,避免了不必要的回调执行。提供两种实现方案并探讨其影响。
8111

被折叠的 条评论
为什么被折叠?



