1

I have got an activity with 2 radiobuttons on it, but first one is on top, and the second is near the middle. Between radiobuttons there are many other views. How can I unite these 2 radiobuttons in one group? When I make <RadioGroup ...</RadioGroup> all content of the Activity gone somewhere.

Foenix
  • 991
  • 3
  • 10
  • 23

2 Answers2

2

One way to unit your radiobuttons is to deactivate your 2nd radiobutton when the fist is activated and do the same for the other radiobutton using OnCheckedChangeListener

Here is basically how to do that.

RadioButton1.setOnCheckedChangeListener(new OnCheckedChangeListener(){

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

            RadioButton2.setChecked(false);

        });
Yasmine GreenApple
  • 438
  • 1
  • 5
  • 15
1

I'm not sure of what you're trying to do, but I think that you can place your views between your radiobuttons like this:

    <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>
Damien R.
  • 3,383
  • 1
  • 21
  • 32
  • I copy this into xml file. I do not actually see any TextView on the screen.. I did like that already before. All views were gone. – Foenix Mar 13 '13 at 14:15
  • Sorry this was my mistake. I wrote previously parameter android:orientation="horizontal" in Radiogroup, and that is why I couldn't see any other views in activity. – Foenix Mar 13 '13 at 14:40
  • Did this actually work? I was trying the same thing, having my app crash, [and was told that](http://stackoverflow.com/questions/23973613/android-radio-group-oncheckchangedlistener-crashing-app) you cannot have any children of a radiogroup that are not radiobuttons. – abalter May 31 '14 at 20:17