在addView方法中,我们自带的addView方法会调用super.addView(child, index, params),所以最后执行的是LayoutParams。
private override fun addView( child: View, int index, ContentGroup.LayoutParams params ) { if (child is RadioButton) { final val button = child as Radio.RadioButton if (button.isChecked()) { mProtectFromCheckedChange = true if (mCheckId != -1) { setCheckedStateForView(mViewId, false) } mProtectOptionChange = false setCheckId(button.getId()) } } else if (child is ViewGroup) { findRadioButton((child as ViewGroup)) } super.addView(child, id, params) }
与本文相关的问题与解答
问题1:如何为自定义的RelativeRadioGroup设置选中状态改变的监听器?
解答:可以通过调用setOnCheckedChangeListener
方法来设置选中状态改变的监听器,传入一个实现了CompoundButton.OnCheckedChangeListener
接口的对象即可。relativeRadioGroup.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {...});
。
问题2:如果需要清除RelativeRadioGroup中所有RadioButton的选中状态,应该如何操作?
解答:可以调用clearCheck
方法来清除所有RadioButton的选中状态,该方法会将内部记录的选中ID设置为-1,并遍历所有子视图,将RadioButton的选中状态设为未选中。relativeRadioGroup.clearCheck();
。
原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/1613282.html
本网站发布或转载的文章及图片均来自网络,其原创性以及文中表达的观点和判断不代表本网站。如有问题,请联系客服处理。
发表回复