3

Hello I want to create RadioGroup that consists of 21 button, but they cant be in one line or column, there should be like 7x3. The problem is that i tried it without RadioGroup and it was fine. I used this xml code

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/darbu_pusl"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".DisplayJobsPage" >

<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="17dp"
    android:layout_marginTop="330dp"
    android:background="@drawable/job_btn_pi"
    android:gravity="left" />

<RadioButton
    android:id="@+id/radioButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/radioButton1"
    android:layout_marginLeft="23dp"
    android:layout_toRightOf="@+id/radioButton1"
    android:background="@drawable/job_btn_a"
    android:gravity="left" />

But now that i try using RadioGroup like this:

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/darbu_pusl"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".DisplayJobsPage">
<RadioButton
    android:id="@+id/radioButton1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginLeft="17dp"
    android:layout_marginTop="330dp"
    android:background="@drawable/job_btn_pi"
    android:gravity="left" />

<RadioButton
    android:id="@+id/radioButton2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/radioButton1"
    android:layout_marginLeft="23dp"
    android:layout_toRightOf="@+id/radioButton1"
    android:background="@drawable/job_btn_a"
    android:gravity="left" />

I am getting warnings that layout_alignTop and layout_toRightOf is invalid layout parameters. Can you guys help me to figure this out? Is it posible to dublicate first layout options in RadioGroup?

Shien
  • 107
  • 4
  • 12

1 Answers1

1

Wrap your RelativeLayout that works within a RadioGroup

ramaral
  • 6,149
  • 4
  • 34
  • 57
  • Thanks that works just fine. I can put in a order that i wanted, but the main problems still exists I can check few buttons. Also getting waring that _"This RelativeLayout layout or its RadioGroup parent is useless; transfer the background attribute to the other view"_ changed to this code below – Shien Dec 08 '13 at 16:51
  • ` ` sorry for my writing style – Shien Dec 08 '13 at 16:51
  • Ok, This doesn't works. RadioGroup uses LinearLayout, which does not wrap. As radio buttons must be direct children to the radio group, you can't add sub-layouts to radio group. – ramaral Dec 08 '13 at 17:23
  • so the only choice would be: ``? is there a way then to control clicks in other radiogroups? I mean if there is a button selected in one radiogroup and then click one in another radiogroup and that one would be selected and previuos would be not. I hope you understood – Shien Dec 08 '13 at 17:34
  • No. RadioGroup is it self a LinearLayout. The only way is to use individual radio buttons and then programmically control there on/off states. – ramaral Dec 08 '13 at 17:46
  • Thanks a lot, i managed to think a work around about this, that would use 3 radiogroups. It wont be the correct choice but it might work :D Thanks again. – Shien Dec 08 '13 at 17:54