1

I'm having problem when I use view flipper to show different xml and each of the xml contains radio button. So actually im in 2 situation I just need either way to work. Situation 1:

I need a 2 by 2 radio button which mean a total of 4 radio button in the position of 2 by 2 and im required to select 1 of them and the other 3 remain unchecked. my question is how can I create in xml that my radio button is all in the same group although somehow I manage to create a 4 radio button they all would not be categories into the same group. Any1 can give me an idea how to categories them into 1 radio group?

Codes: 
<RadioGroup
            android:id="@+id/rg1"
            android:layout_height="0dp"
            android:layout_width="fill_parent"
            android:baselineAligned="false"
            android:layout_weight="2.5"
            android:orientation="horizontal">
                <LinearLayout 
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical"
                    android:layout_weight="1">
                    <RadioButton
                        android:id="@+id/radio0"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:checked="true"
                        android:text="@string/radio1" 
                        android:textColor="#000000"
                        android:button="@drawable/radiobutton"
                        android:clickable="true"
                        android:layout_weight="1"
                        android:paddingLeft="45dp"/>
                    <RadioButton
                        android:id="@+id/radio1"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:text="@string/radio2" 
                        android:textColor="#000000"
                        android:button="@drawable/radiobutton"
                        android:clickable="true"
                        android:layout_weight="1"
                        android:paddingLeft="45dp"/>
                </LinearLayout>
                <LinearLayout 
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:orientation="vertical"
                    android:layout_weight="1">
                    <RadioButton
                        android:id="@+id/radio2"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:text="@string/radio3" 
                        android:textColor="#000000"
                        android:button="@drawable/radiobutton"
                        android:clickable="true"
                        android:layout_weight="1"
                        android:paddingLeft="45dp"/>
                    <RadioButton
                        android:id="@+id/radio3"
                        android:layout_width="wrap_content"
                        android:layout_height="fill_parent"
                        android:text="@string/radio4" 
                        android:textColor="#000000"
                        android:button="@drawable/radiobutton"
                        android:clickable="true"
                        android:layout_weight="1"
                        android:paddingLeft="45dp"/>
                </LinearLayout>
            </RadioGroup>

Situation 2:

The second Situation is that I try clearing the radio buttons using codes nut somehow when I flip to another xml with the same radio button and id but it wont work.

PS: Sorry for my bad command of english

  • what do you mean by "different categories"? – C. Leung Apr 20 '12 at 04:19
  • because if u put into 1 radio group then we will be only be able select 1 at a time but now i can select all 4 as stated above of my codes for my xml – I Yeu Cheong Apr 20 '12 at 04:58
  • I know what you mean after trying out your code. your `RadioButton` are in the same category as they are all in the same `RadioGroup`. however, they need to be the immediate children of the `RadioGroup` in order to have the behavior of "1 on, 3 off". if you remove the `LinearLayout`, it should work fine; but of course, it is no longer 2 x 2 in layout. – C. Leung Apr 20 '12 at 07:17
  • so if you want a 2 x 2 `RadioGroup`, try the method in [this post](http://stackoverflow.com/questions/2381560/how-to-group-a-3x3-grid-of-radio-buttons). – C. Leung Apr 20 '12 at 07:20
  • okay :) is also a gd way is much better than my way i think :X thx :D – I Yeu Cheong Apr 20 '12 at 08:15

0 Answers0