Android disable radio group in xml

南笙酒味 提交于 2019-12-23 18:29:33

问题


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


回答1:


Use the following attribute

android:clickable="false"   



回答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);      
}


来源:https://stackoverflow.com/questions/15921711/android-disable-radio-group-in-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!