Android RadioGroup 检查多个 RadioButton?多个、Android、RadioGroup、RadioButton

2023-09-06 19:34:44 作者:俄為自己帶盐

我正在使用 RadioGroup,将 RadioButton rdbut 添加到 RadioGroup rdgrp,如 rdgrp.addView(rdbut).

I am using RadioGroup, added RadioButton rdbut to RadioGroup rdgrp like rdgrp.addView(rdbut).

   for(int j=0;j<3;j++)
   {
         RadioGroup rdgrp = new RadioGroup;
         for(int i=0;i<=10;i++)
         {
             RadioButton rdbut = new RadioButton(this);
             rdbut.setText("RadioButtion"+i);
             rdbut.setId(i);
             rdbut.setTag("somename");
             rdgrp.addView(rdbut);
         }
    }    

上面的代码显示了我如何初始化单选组和单选按钮.在 emulator/mobile 中运行此代码后,我可以一次检查 2 个单选按钮.

the above code shows how I initialize the radiogroup and radio button. after I run the this code, in emulator/mobile , i am able to check 2 radio buttons at a time.

可能是什么问题?

推荐答案

像这样改变你的代码.

  RadioGroup rdgrp[] = new RadioGroup[3];

  For(int j=0;j<3;j++)
   {
         RadioButton rdbut[] = new RadioButton[10];
         For(int i=0;i<=10;i++)
         {

             rdbut[i].setText("RadioButtion"+i);
             rdbut[i].setId(j*100+i);
             rdbut[i].setTag("somename");
             rdgrp[j].addView(rdbut[i]);
         }
    } 
 
精彩推荐
图片推荐