0

I need to create design like radiobutton in multi-row in single radiogroup like this image .

I am using android:orientation="horizontal"

layout.xml

 <RadioGroup
        android:id="@+id/radiogroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/option1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:singleLine="false"
            android:text="option1" />

        <RadioButton
            android:id="@+id/option2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:singleLine="false"
            android:text="option2" />

        <RadioButton
            android:id="@+id/option3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:singleLine="false"
            android:text="option3" />

        <RadioButton
            android:id="@+id/option4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:singleLine="false"
            android:text="option4" />

        <RadioButton
            android:id="@+id/option5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:singleLine="false"
            android:text="option5" />

        <RadioButton
            android:id="@+id/option6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:singleLine="false"
            android:text="option6" />
    </RadioGroup>

Thanks..

2 Answers2

0

What you are trying to achieve is possible. You will have to subclass TableLayout and add the radio buttons programmatically

here is the link

refer this MATRIX RADIO BUTTONS

For screen width

Screen Width

Community
  • 1
  • 1
WISHY
  • 11,067
  • 25
  • 105
  • 197
  • I am using same but I added three radiobutton in single tablerow but its not appear because small width of screen, is it possible to set item in single according to screen width automatically – user3891275 Aug 01 '14 at 07:27
  • I had used it before. And it works on the small screen size also. – WISHY Aug 01 '14 at 08:22
  • it is working but I have to fix number of item in row, but I want automatic to screen width like as small screen then 3 item in one row, large screen then 4 item in one row, xtra large then 5 item in one row.. – user3891275 Aug 01 '14 at 08:38
  • For that you will have to define your parameters . You can get screen width by http://stackoverflow.com/questions/1016896/how-to-get-screen-dimensions – WISHY Aug 01 '14 at 08:42
0

parent can be any like linear horizontal or relative(i'd prefer Linear Horizontal), inside that 3 TableRow childs,within each tableRow your RadioButtons. something like this

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
    <RadioGroup>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Radio1"
            />
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Radio2"/>
        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Radio3"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio4"
                />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio5"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio6"/>
        </LinearLayout>
    </RadioGroup>
</TableRow>
<TableRow android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
    <RadioGroup>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio1"
                />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio2"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio3"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            >
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio4"
                />
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio5"/>
            <RadioButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Radio6"/>
        </LinearLayout>
    </RadioGroup>
</TableRow>

  • it is working but I have to fix number of item in row, but I want automatic to screen width like as small screen then 3 item in one row, large screen then 4 item in one row, xtra large then 5 item in one row.. – user3891275 Aug 01 '14 at 08:45
  • 1
    this is not working in radiogroup, if I check any radiobutton then other radiobutton doesn't unchecked automatically – user3891275 Aug 01 '14 at 08:46