mRgNavi = (RadioGroup) findViewById(R.id.rg_navi);
for (int i = 0; i < 10; i++) {
RadioButton tempButton = new RadioButton(this);
tempButton.setBackgroundResource(R.drawable.tanwei1_selector); // 设置RadioButton的背景图片
tempButton.setButtonDrawable(null); // 设置按钮的样式
// tempButton.setPadding(80, 0, 0, 0); // 设置文字距离按钮四周的距离
tempButton.setText("摊位 " + i + " (" + i + "单"+")");
mRgNavi.addView(tempButton, LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
if (i == 0) {
// radioGroup.check(radioButton.getId());
tempButton.setChecked(true);
}
}
RadioGroup动态添加RadioButton,RadioButton设置默认选中第一个,点击其他的RadioButton第一个不再选中,第一个不再选中
最新推荐文章于 2023-06-04 06:00:00 发布