5 private LinearLayout layout; //布局 , 可以在xml布局中获得 6 private RadioGroup group ; //点选按钮组 7 8 public void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); 10 11 layout = new LinearLayout(this); //实例化布局对象 12 13 group = new RadioGroup(this); //实例化单选按钮组 14 15 //添加单选按钮 16 for(int i = 0 ; i < 5 ; i++){ 17 RadioButton radio = new RadioButton(this); 18 radio.setText("radio" + i); 19 group.addView(radio); 20 } 21 22 //将单选按钮组添加到布局中 23 layout.addView(group); 24 25 this.setContentView(layout); 26 }
动态添加RADIOBUTTON
最新推荐文章于 2024-05-22 12:13:56 发布