1

我有一个带有 2 个单选按钮的活动,但第一个在顶部,第二个在中间附近。在单选按钮之间还有许多其他视图。如何将这 2 个单选按钮合并为一组?当我<RadioGroup ...</RadioGroup>将 Activity 的所有内容都放到某个地方时。

4

2 回答 2

2

组合单选按钮的一种方法是在激活拳头时停用第二个单选按钮,并使用其他单选按钮执行相同操作OnCheckedChangeListener

这里基本上是如何做到这一点的。

RadioButton1.setOnCheckedChangeListener(new OnCheckedChangeListener(){

            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // TODO Auto-generated method stub

            RadioButton2.setChecked(false);

        });
于 2013-03-13T14:08:12.980 回答
1

我不确定您要做什么,但我认为您可以将视图放在单选按钮之间,如下所示:

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

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <RadioButton
                android:id="@+id/RB1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="text1" />

            <TextView
                android:id="@+id/textview"
                android:text="Place your many other views like this" />

            <RadioButton
                android:id="@+id/RB2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="text2" />
        </LinearLayout>
    </RadioGroup>
于 2013-03-13T14:01:01.873 回答