Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/197.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单选分组/按钮查询_Android_Radio Button - Fatal编程技术网

Android 单选分组/按钮查询

Android 单选分组/按钮查询,android,radio-button,Android,Radio Button,当我使用view flipper显示不同的xml并且每个xml都包含单选按钮时,我遇到了问题。所以实际上我处于两种情况下,我只需要两种方式来工作。 情景1: 我需要一个2乘2单选按钮,这意味着总共有4个单选按钮在2乘2的位置,im需要选择其中一个,其他3个保持未选中状态。我的问题是如何在xml中创建我的单选按钮都在同一个组中,尽管我设法创建了一个4个单选按钮,但它们都不会属于同一个组中的类别。任何人都可以给我一个想法,如何将他们分为一个广播组 Codes: <RadioGroup

当我使用view flipper显示不同的xml并且每个xml都包含单选按钮时,我遇到了问题。所以实际上我处于两种情况下,我只需要两种方式来工作。 情景1:

我需要一个2乘2单选按钮,这意味着总共有4个单选按钮在2乘2的位置,im需要选择其中一个,其他3个保持未选中状态。我的问题是如何在xml中创建我的单选按钮都在同一个组中,尽管我设法创建了一个4个单选按钮,但它们都不会属于同一个组中的类别。任何人都可以给我一个想法,如何将他们分为一个广播组

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>
情景2:

第二种情况是,当我切换到另一个具有相同单选按钮和id的xml时,我尝试以某种方式使用代码清除单选按钮,但它不起作用


PS:很抱歉我的英语水平不好

你说的不同类别是什么意思?因为如果你加入一个广播组,那么我们一次只能选择一个,但是现在我可以选择我的XML的所有4个代码了,我知道你在试过代码后的意思。您的单选按钮属于同一类别,因为它们都属于同一放射组。然而,他们必须是放射组的直系子代,才能有1开3关的行为。如果移除线性布局,它应该可以正常工作;但是,当然,它不再是布局中的2x2。因此,如果您想要2x2放射组,请尝试中的方法。好的:也是gd方法比我认为的要好得多:x thx:D