How to disable radiobutton's text from clickable feature? - android

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>

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.
Only way is by making your own class. Let me know if this answered your question.
:)

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>

Related

Radio Group android

I started to develop for Android few days ago and I got stuck trying to use Radio Group. In my code for some reason all of the radio buttons can be selected together.
Any suggestion?
xml:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/rG">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="89dp"
android:layout_below="#id/title"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="95"
android:layout_marginLeft="75sp"
android:layout_marginTop="20sp"
android:id="#+id/rb95"
android:layout_gravity="left|top"
android:checked="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="98"
android:id="#+id/rb98"
android:layout_gravity="right|top"
android:layout_alignTop="#+id/rb95"
android:layout_alignLeft="#+id/rbs"
android:layout_alignStart="#+id/rbs"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="96"
android:id="#+id/rb96"
android:layout_gravity="left"
android:layout_below="#id/rb95"
android:layout_alignLeft="#id/rb95"
android:layout_alignStart="#id/rb95"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="soler"
android:id="#+id/rbs"
android:layout_gravity="right"
android:layout_marginRight="75dp"
android:layout_alignTop="#id/rb96"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</RadioGroup>
Pull the RadioButtons out of the RelativeLayout (get completely rid of it: it's not only misplaced, but also useless) and they will work as expected.
If you really need the RelativeLayout as a container for the RadioGroup, then swap the RelativeLayout and RadioGroup (RelativeLayout on the outside)
I think your problem is that you have a relativeLayout inside your RadioGroup.
Here is the Google Developer page on radio buttons.

android layout radiogroup position

I have radiogroup :
<RadioGroup android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#drawable/overlay_2"
android:id="#+id/rgSettings">`
<RadioButton android:layout_width="140dp"
android:layout_height="100dp"
android:id="#+id/s_mph"
android:background="#drawable/settings_speed_mph"
android:button="#android:color/transparent"
android:layout_gravity="center_vertical|left"/>
<RadioButton android:layout_width="140dp"
android:layout_height="100dp"
android:id="#+id/s_kph"
android:checked="false"
android:background="#drawable/settings_speed_kph"
android:button="#android:color/transparent"
android:layout_gravity="center"
android:gravity="right"/>
</RadioGroup>
Link in screenshot : http://joxi.ru/A5GhUxjKTJBQH7uRaK4
(1) radiogroup
(2) - (3) its radio buttons.
I need radibutton (2) set in position - left, radiobutton (3) set in right position. What do I need for this?
Add:
i need set first button set left position in radiogroup, secondary button set in right position radiogroup. Like This: joxi.ru/FqKhUxjKTJBsH5OWteQ
Why You are setting the button that You need on the left side as first? Just switch it:
<RadioGroup android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_width="match_parent"
android:background="#drawable/overlay_2"
android:id="#+id/rgSettings">
<RadioButton android:layout_width="140dp"
android:layout_height="100dp"
android:id="#+id/s_kph"
android:checked="false"
android:background="#drawable/settings_speed_kph"
android:button="#android:color/transparent"
android:layout_gravity="center_vertical|left"
android:gravity="right"/>
<RadioButton android:layout_width="140dp"
android:layout_height="100dp"
android:id="#+id/s_mph"
android:background="#drawable/settings_speed_mph"
android:button="#android:color/transparent"
android:layout_gravity="center_vertical|right"/>
</RadioGroup>
Also, You can play a little bit with the layout_margin attributes to make space between the buttons.

How to reduce space between radiobuttons in a radiogroup in android?

In my app, I have a dialog that contains a radiogroup with four radio buttons. My issue is that it looks good in emulator but when I install and run my app in phone, the radiobuttons get more space between each one of them. This makes the radiogroup stretch outside of my Dialog.
Please help me with this.
Thank you.
<RadioGroup
android:id="#+id/radio_RemindAtDlg"
android:layout_width="wrap_content"
android:layout_height="130dp"
android:layout_marginTop="110dp"
android:layout_marginLeft="20dp" >
<RadioButton
android:id="#+id/radio_OnceDlg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Once"
android:button="#drawable/radio_button"
android:textSize="12dp" />
<RadioButton
android:id="#+id/radio_WeekDlg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Every Week"
android:button="#drawable/radio_button"
android:textSize="12dp" />
<RadioButton
android:id="#+id/radio_MonthDlg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Every Month"
android:button="#drawable/radio_button"
android:textSize="12dp" />
<RadioButton
android:id="#+id/radio_YearDlg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Every Year"
android:button="#drawable/radio_button"
android:textSize="12dp" />
</RadioGroup>
Define your own radio buttons with your own sizes, shapes and spaces between components:
http://blog.devminded.com/posts/custom-android-radiobutton
another example
https://stackoverflow.com/a/17693303/1276374
Without code hard to tell but I would guess that you have the xml height attribute set to fill_parent instead of wrap_content

Have horizontal RadioButtons wrap if too long for screen

So I have the following radiobuttons. I want to have them display like this:
However this occurs:
How I can get it to display like above? I can move in the GUI editor in Eclipse it but it removes the RadioButton from the RadioGroup!Within the group, it ignores all other layout parameters.
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/timeBar"
android:layout_marginTop="43dp"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/privRadio0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Everyone" />
<RadioButton
android:id="#+id/privRadio1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="FriendOfFriends" />
<RadioButton
android:id="#+id/privRadio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friends" />
</RadioGroup>
You can simply copy this class:
https://github.com/jevonbeck/AbstractMachine/blob/jevon_dev/app/src/main/java/org/ricts/abstractmachine/ui/utils/MultiLineRadioGroup.java
into an appropriate package in your project and instantiate in XML like so:
<view
class="mypackage.packagepath.MultiLineRadioGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
What you are asking for is a FlowLayout. Such a layout has the benefit of only wrapping when it's needed, as opposed to 0gravity's more "static" solution.

Android RadioButton like Behaviour

Greetings,
I'm trying to create a single-choice android control, in a horizontal layout, by making use of the RadioGroup behaviour. I can assign the drawable just fine, but i would like to position the label of each RadioButton inside the drawable, is this possible using the standard APIs?
<RadioGroup
android:id="#+id/switchcontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:checkedButton="#+id/RadioButton02"
android:padding="3dip">
<RadioButton
android:text="id RadioButton02"
android:id="#+id/RadioButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/radio_button"
android:paddingRight="2dip" />
<RadioButton
android:text="#+id/RadioButton03"
android:id="#+id/RadioButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#drawable/radio_button"
android:paddingRight="2dip" />>
</RadioGroup>
Okay, i found a way.
Just use #null in the attribute button, and move the drawable reference to the attribute background like this:
<RadioGroup
android:id="#+id/switchcontainer"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:checkedButton="#+id/RadioButton02">
<RadioButton
android:text="id RadioButton02"
android:id="#+id/RadioButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/radio_button"
android:button="#null"/>
<RadioButton
android:text="#+id/RadioButton03"
android:id="#+id/RadioButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/radio_button"
android:button="#null"/>
</RadioGroup>
I'm not sure about with the RadioGroup; however, it should be possible to accomplish this with a ListView.
Set the ListView choiceMode to singleChoice.
Provide an ArrayAdapter or SimpleAdapter with a custom layout file for the row. This allows you to configure the position of the label.
For a quick intro to ListView's, see Hello ListView

Categories

Resources