Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android disable radio group in xml

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

like image 259
Linga Avatar asked Apr 10 '13 09:04

Linga


2 Answers

Use the following attribute

android:clickable="false"   
like image 116
datalost Avatar answered Sep 21 '22 07:09

datalost


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);      
}
like image 22
dharam Avatar answered Sep 19 '22 07:09

dharam