0

I need to select radio button while touching only the icon of a radio button. By default when i touch on the radio button's text, the radio button also get checked. How can i disable the feature?

   <RadioGroup
            android:id="@+id/optionGroup"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <RadioButton
                android:id="@+id/radio1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:checked="true"
                android:text="RadioButton"
                android:textColor="@color/optionText"
                android:textSize="@dimen/text_exam"
                android:gravity="top" />           
            <RadioButton
                android:id="@+id/radio2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:textColor="@color/optionText"
                android:textSize="@dimen/text_exam"
                android:gravity="top"    />

            <RadioButton
                android:id="@+id/radio3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:textColor="@color/optionText"
                android:textSize="@dimen/text_exam"
                android:gravity="top"       />

            <RadioButton
                android:id="@+id/radio4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RadioButton"
                android:textColor="@color/optionText"
                android:textSize="@dimen/text_exam"
                android:gravity="top"    />

        </RadioGroup>
JITHIN GOPAL
  • 131
  • 1
  • 14

2 Answers2

3

To answer your question, you can't do it using the default radiobutton class.

The android-radiobutton is an object of the class which actually makes the radiobutton itself. This class sets the properties of the RadioButton, and, to a certain extent, you cannot change these properties. You can, however, make it unclickable, change the color, set the text, however, you cannot change what portion of the button is clickable. To do that, you must make your own class of a RadioButton, and extend it to the class that you are using.

enter image description here

Only way is by making your own class. Let me know if this answered your question.

:)

Ruchir Baronia
  • 7,406
  • 5
  • 48
  • 83
2

Try this simple hack

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <RadioButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="RadioButton"/>

    </LinearLayout>
Bhargav Thanki
  • 4,924
  • 2
  • 37
  • 43
  • The problem with that solution is that if you have multiple radio buttons, you would be able to click them all at the same time, leaving you with something like a checkbox (you cannot uncheck though). – hehe Dec 23 '15 at 05:30