xml - 如何将单选组添加到表格内的单选按钮?

标签 xml android

我有多个单选按钮,我想使用表格对其进行布局,但也将它们包含在一个单选按钮组中。我有以下 xml 布局:

<RadioGroup android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"
      android:id="@+id/Group1">

    <TableLayout android:id="@+id/RadioButtons" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">

        <TableRow>
            <RadioButton android:id="@+id/rad1" 
                android:text="RButton1" 
                android:layout_width="105px" 
                android:layout_height="wrap_content" 
                android:textSize="13px"></RadioButton>
            <RadioButton android:id="@+id/rad2" 
                android:text="RButton2" 
                android:layout_width="105px" 
                android:textSize="13px" 
                android:layout_height="wrap_content"></RadioButton>
            <RadioButton android:id="@+id/rad3" 
                android:text="RButton3" 
                android:layout_width="105px" 
                android:textSize="13px" 
                android:layout_height="wrap_content"></RadioButton>
        </TableRow>
      </TableLayout>
</RadioGroup>  

但不幸的是,表格内的单选按钮似乎忽略了它们位于 RadioGroup 标签内这一事实,因此您可以同时选择多个单选按钮。我注意到,通过删除表格并仅使用单选按钮,它就可以正常工作。我怎样才能克服这个?它会像在表内而不是表外声明 radio 组一样简单吗?谢谢你的帮助。

最佳答案

您的 RadioButton 小部件必须是 RadioGroup 的直接子级才能使组效果起作用。

关于xml - 如何将单选组添加到表格内的单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2361205/

相关文章:

javascript - 无法获取属性值 'nodeValue' : object is null or undefined in IE

xml - Xpath 获取当前节点的值

java - 当我将默认的 xml 布局文件更改为另一个时,Android 应用程序崩溃

android - google-api-services-translate 和 google-cloud-translate 做同样的事情吗?

java - 如何设置RelativeLayout背景颜色?

java - android fragment 可以在api 3.0上使用,但不能在2.2上使用

xml - 通过在 Xpath 中动态传递节点名称来获取节点值

android - 我们如何知道 Android 应用程序已关闭?

android - android studio中的庆祝动画

java - 是否有必要用 Dagger 2 注入(inject)一切?