Android 动态赋值RadioBox 资源ID

generateViewId()。

代码示例:

 for (int i = 0; i < list_house_data.size(); i++) {
            // 先获得checkbox.xml的对象
            MaterialRadioButton radioBox = (MaterialRadioButton) getLayoutInflater().inflate(
                    R.layout.radiobox, null);

            radioBox.setId(generateViewId());
            if (list_house_data.get(i).getValue().equals(selectVal) ) {
                radioBox.setChecked(true);

            }
 
            radioBox.setText(list_house_data.get(i).getName());
 
            rgp_group.addView(radioBox, i);
        }
发布了76 篇原创文章 · 获赞 21 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/u010227042/article/details/104583647