Zerho
Zerho

Reputation: 1460

RadioButton select not working

Hi there, i have those 4 radio buttons in 2 different RadioGroup and i need as usual that only one per group can be selected, but it doesn't work, any suggestions?

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1" android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableLayout android:background="#ffffff"
        android:layout_width="match_parent" android:layout_height="match_parent"
        android:stretchColumns="1">
        <RadioGroup android:layout_width="match_parent"
            android:layout_height="wrap_content" android:orientation="vertical"
            android:id="@+id/radGroupDep">
            <TableRow>
                <RadioButton android:id="@+id/radDepAir"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:gravity="left"></RadioButton>
                <Spinner android:id="@+id/spinDepAir" android:layout_height="wrap_content"
                    android:layout_width="match_parent" android:gravity="right"></Spinner>
            </TableRow>
            <TableRow>
                <RadioButton android:id="@+id/radDepTow"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:gravity="left"></RadioButton>
                <Spinner android:id="@+id/spinDepReg" android:layout_height="wrap_content"
                    android:layout_width="match_parent" android:gravity="right"></Spinner>
            </TableRow>
        </RadioGroup>
        <RadioGroup android:layout_width="match_parent"
            android:layout_height="wrap_content" android:orientation="vertical"
            android:id="@+id/radGroupArr">
            <TableRow>
                <RadioButton android:id="@+id/radArrAir"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:gravity="left"></RadioButton>
                <Spinner android:id="@+id/spinArrAir" android:layout_height="wrap_content"
                    android:layout_width="match_parent" android:gravity="right"></Spinner>
            </TableRow>
            <TableRow>
                <RadioButton android:id="@+id/radArrTow"
                    android:layout_width="wrap_content" android:layout_height="wrap_content"
                    android:gravity="left"></RadioButton>

                <Spinner android:id="@+id/spinArrReg" android:layout_height="wrap_content"
                    android:layout_width="match_parent" android:gravity="right"></Spinner>
            </TableRow>
        </RadioGroup>
    </TableLayout>
</ScrollView>

Upvotes: 0

Views: 771

Answers (1)

Kundan Chaudhary
Kundan Chaudhary

Reputation: 833

apply this code..it's work fine..some change in your code.may be helpful

i am use relative layout instead of table layout....

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" android:weightSum="1">
    <ScrollView android:id="@+id/scrollView1"
        android:layout_width="match_parent" android:layout_height="wrap_content">
        <RelativeLayout android:id="@+id/relativeLayout1"
            android:layout_width="match_parent" android:layout_height="wrap_content">
            <RadioGroup android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:id="@+id/radioGroup1"
                android:layout_alignParentTop="true" android:layout_alignParentLeft="true">
                <RadioButton android:layout_height="wrap_content"
                    android:id="@+id/radio0" android:layout_width="wrap_content"
                    android:checked="true"></RadioButton>
                <RadioButton android:layout_height="wrap_content"
                    android:id="@+id/radio1" android:layout_width="wrap_content"></RadioButton>
            </RadioGroup>
            <Spinner android:layout_width="wrap_content" android:id="@+id/spinner1"
                android:layout_height="wrap_content" android:layout_alignParentTop="true"
                android:layout_toRightOf="@+id/radioGroup1"
                android:layout_marginLeft="16dp"></Spinner>
            <Spinner android:layout_width="wrap_content" android:id="@+id/spinner4"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" android:layout_alignLeft="@+id/spinner1"></Spinner>
            <RadioGroup android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:id="@+id/radioGroup2"
                android:layout_below="@+id/spinner2" android:layout_toLeftOf="@+id/spinner1">
                <RadioButton android:layout_height="wrap_content"
                    android:checked="true" android:id="@+id/radio3"
                    android:layout_width="wrap_content"></RadioButton>
                <RadioButton android:layout_height="wrap_content"
                    android:id="@+id/radio4" android:layout_width="wrap_content"></RadioButton>
            </RadioGroup>
            <Spinner android:layout_width="wrap_content" android:id="@+id/spinner2"
                android:layout_height="wrap_content" android:layout_below="@+id/spinner1"
                android:layout_alignLeft="@+id/spinner1"></Spinner>
            <Spinner android:layout_width="wrap_content" android:id="@+id/spinner3"
                android:layout_height="wrap_content" android:layout_alignTop="@+id/radioGroup2"
                android:layout_alignLeft="@+id/spinner2"></Spinner>
        </RelativeLayout>
    </ScrollView>
</LinearLayout>

Upvotes: 1

Related Questions