5

In my android application, I need to disable radio group in xml layout. I searched, but I found only through pro-grammatically not in xml layout.

My code is here

<RadioGroup
        android:id="@+id/menu1"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_x="170dp"
        android:layout_y="100dp" >

        <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Yes" />

        <RadioButton
            android:id="@+id/radioButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="No" />
</RadioGroup>

I've tried with android:enabled="false" but it is not supported by Radio Group. But it works in RadioButton as

      <RadioButton
            android:id="@+id/radioButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:enabled="false"
            android:text="Yes" />

Now my question is If my RadioGroup contains 10 RadioButtons, I want to set enable=false only for the RadioGroup, not for every individual RadioButton. So how can I disable the entire RadioGroup instead of disabling RadioButtons?

I need only in xml layout. Thanks in advance

Linga
  • 10,379
  • 10
  • 52
  • 104

2 Answers2

7

Use the following attribute

android:clickable="false"   
Linga
  • 10,379
  • 10
  • 52
  • 104
datalost
  • 3,765
  • 1
  • 25
  • 32
  • 1
    This worked for me, but you have to add it to each RadioButton, and not the RadioGroup. – Gober Sep 02 '14 at 11:11
2

You are absolutely right there is no property given for radio group for disable it.

you can not find any method to do like in this developer site LINK

Now my question is If my RadioGroup contains 10 RadioButtons, I want to set enable=false only for the RadioGroup, not for every individual RadioButton. So how can I disable the entire RadioGroup instead of disabling RadioButtons?

All you can do to disable it is in java code of activity .

for (int i = 0; i <group.getChildCount(); i++) 
{
    group.getChildAt(i).setEnabled(false);      
}
dharmendra
  • 7,835
  • 5
  • 38
  • 71