简体   繁体   中英

RadioGroup with radiobuttons inside a relative android layout

I want to create a simple layout like the following:

(o) Radio button A
(o) Radio button B [textedit]
    [x] checkbox

For that I've created the following layout.xml:

<RadioGroup 
    android:layout_above="@+id/RadioButton_Count" 
    android:id="@+id/RadioGroup01" 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent">
    <RadioButton 
        android:layout_height="wrap_content" 
        android:id="@+id/RadioButton_A" 
        android:text="Play forever" 
        android:checked="true" 
        android:layout_width="fill_parent" 
        android:textSize="20sp">
    </RadioButton>
    <RelativeLayout 
        android:id="@+id/RelativeLayout01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content">
        <RadioButton 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/RadioButton_B" 
            android:text="Count:" 
            android:textSize="20sp">
        </RadioButton>
        <EditText 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/EditText_NumCount" 
            android:inputType="number" 
            android:layout_toRightOf="@+id/RadioButton_B" 
            android:width="70sp" >
        </EditText>
        <CheckBox 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/CheckBox_StopCount" 
            android:text="Stop" 
            android:layout_below="@+id/RadioButton_B" 
            android:textSize="18sp">
        </CheckBox>
    </RelativeLayout>
</RadioGroup>

It looks right, but the problem is that the radiobuttons doesn't connect between each other, i mean that they can be both on in the same moment. I think it's because even if they're hanging from the same the second one is inside another layout :\\ Does anyone have some idea how could I make this kind of layout (Mainly the [textedit] just right the RadioButton B), getting working also the radiobuttons? Thank you very much

You simply can't do it. I was also trying to do something similar and got stuck.

"RadioButtons have to be direct children of RadioGroup." https://code.google.com/p/android/issues/detail?id=1214

The first thing to try is to close your RadioGroup right after you close the last RadioButton instead of at the end. A better solution is to use a RelativeLayout as the overall container. Next add your RadioGroup and both buttons and close the group. Add the other elements relative to the rest of the layout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM