Android RadioGroup checks more than one RadioButton?

て烟熏妆下的殇ゞ 提交于 2019-12-02 03:59:00

Change your code like this.

  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]);
         }
    } 

You have created three different Radio Group. You can select only one radio button from a single group.So from three groups you can select three buttons But there is no inter-group relationship. You can select radio buttons from different group simultaneously. In your case you can select three buttons at max.

Thanks Sunil

Use Some thing like this xml design in user layout file.

   <TableLayout
            android:id="@+id/tbl_layoutchoice"
            style="@style/InfoTableView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="3dip" >

            <RadioGroup
                android:id="@+id/SelectLayout_Group"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >
            </RadioGroup>
 </TableLayout>

and For Use this RadioGroup in Activity 's OnCreate() Method and findView like this

 mRadioGroup = (RadioGroup) this.findViewById(R.id.SelectLayout_Group);

and Then Use Below Code With Your Require Change To Add Radio Button in One RadioGroup.Use Also Below Require Declaration for Create Radio Button Dynamically.

     ArrayList<String> layoutlist = new ArrayList<String>(3);
     int index = -1;
     LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
        LayoutParams.WRAP_CONTENT);


   for (String layout : layoutlist) {
        RadioButton r = new RadioButton(this);
        index++;
        r.setText(layout);
        r.setId(index);
        r.setLayoutParams(lp);
        r.setTextAppearance(this, R.style.TextBase);


        mRadioGroup.addView(r);


    }

So don't forget to add your String Value in layoutlist before for loop .and R.style is some Require Style for Text Show in RadioButton.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!