RadioGroup中不能正常工作 [英] RadioGroup doesn't work properly

查看:315
本文介绍了RadioGroup中不能正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想给用户四个选择,在一个行的第一和第二选择和对另一行的第三和第四选择。我的问题是,当应用程序启动时,我可以选择多个选择,但我不希望这样。这是我的XML布局:

I want to give the user four choices, the first and second choices on a row and the third and fourth choices on another row. My problem is when the application starts I can select more than one choice, but I don't want that. This is my xml layout:

<RadioGroup
        android:id="@+id/rgAnswerQuestionChoices"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/rAnswerQuestonChoic1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:visibility="invisible" />

            <RadioButton
                android:id="@+id/rAnswerQuestionChoice2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:visibility="invisible" />
        </LinearLayout>

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:orientation="horizontal" >

            <RadioButton
                android:id="@+id/rAnswerQuestionChoice3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:visibility="invisible" />

            <RadioButton
                android:id="@+id/rAnswerQuestionChoice4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:visibility="invisible" />
        </LinearLayout>
    </RadioGroup>

我在做什么错了?

What am I doing wrong?

推荐答案

如果您将单选按钮等之间的布局父 RadioGroup中(如你与那些没有 LinearLayouts ),那么互斥就不管用了。

If you place other layouts between the RadioButtons and the parent Radiogroup(like you did with those LinearLayouts) then the mutual exclusion will not work anymore.

把那些单选按钮在两排桌子,你可以让自己的 RadioGroup中其中地方单选按钮像你想要的或者你可以尝试通过其来模拟布局两个 RadioGroups 这表现为一个(例如,<一个href=\"http://stackoverflow.com/questions/10425569/radiogroup-with-two-columns-which-have-ten-radiobuttons\">RadioGroup其中有十个单选按钮有两列的)。

To put those RadioButtons in a two rows table you could make your own RadioGroup which places the RadioButtons like you want or you can try to simulate that layout by having two RadioGroups that behave as one(for example, RadioGroup with two columns which have ten RadioButtons).

这篇关于RadioGroup中不能正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆