RadioGroup with two columns which have ten RadioButtons

You can simulate that RadioGroup to make it look like you have only one. For example you have rg1 and rg2(RadioGroups with orientation set to vertical(the two columns)). To setup those RadioGroups: rg1 = (RadioGroup) findViewById(R.id.radioGroup1); rg2 = (RadioGroup) findViewById(R.id.radioGroup2); rg1.clearCheck(); // this is so we can start fresh, with no selection on both RadioGroups … Read more

Android: RadioGroup – How to configure the event listener

This is how you get the checked radiobutton: // This will get the radiogroup RadioGroup rGroup = (RadioGroup)findViewById(r.id.radioGroup1); // This will get the radiobutton in the radiogroup that is checked RadioButton checkedRadioButton = (RadioButton)rGroup.findViewById(rGroup.getCheckedRadioButtonId()); To use the listener, you do this: // This overrides the radiogroup onCheckListener rGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int … Read more

How to get the selected index of a RadioGroup in Android

You should be able to do something like this: int radioButtonID = radioButtonGroup.getCheckedRadioButtonId(); View radioButton = radioButtonGroup.findViewById(radioButtonID); int idx = radioButtonGroup.indexOfChild(radioButton); If the RadioGroup contains other Views (like a TextView) then the indexOfChild() method will return wrong index. To get the selected RadioButton text on the RadioGroup: RadioButton r = (RadioButton) radioButtonGroup.getChildAt(idx); String selectedtext = … Read more

How to group RadioButton from different LinearLayouts?

It seems that the good people at Google/Android assume that when you use RadioButtons, you don’t need the flexibility that comes with every other aspect of the Android UI/layout system. To put it simply: they don’t want you to nest layouts and radio buttons. Sigh. So you gotta work around the problem. That means you … Read more

Multiple radio button groups in one form

Set equal name attributes to create a group; <form> <fieldset id=”group1″> <input type=”radio” value=”value1″ name=”group1″> <input type=”radio” value=”value2″ name=”group1″> </fieldset> <fieldset id=”group2″> <input type=”radio” value=”value1″ name=”group2″> <input type=”radio” value=”value2″ name=”group2″> <input type=”radio” value=”value3″ name=”group2″> </fieldset> </form>

How to set OnClickListener on a RadioButton in Android?

I’d think a better way is to use RadioGroup and set the listener on this to change and update the View accordingly (saves you having 2 or 3 or 4 etc listeners). RadioGroup radioGroup = (RadioGroup) findViewById(R.id.yourRadioGroup); radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected } … Read more

Reset a Radio button inside a Radio group

try this : radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) { if (checkedId == R.id.radioButton){ //do something } else if(checkedId == R.id.radioButton2){ } else{ } }); xml layout <RadioGroup android:layout_width=”fill_parent” android:layout_height=”90dp” android:layout_below=”@+id/imageView” android:layout_marginTop=”58dp” android:weightSum=”1″ android:id=”@+id/radioGroup” android:layout_alignLeft=”@+id/textView2″ android:layout_alignStart=”@+id/textView2″ android:layout_alignRight=”@+id/textView3″ android:layout_alignEnd=”@+id/textView3″> <RadioButton android:layout_width=”wrap_content” android:layout_height=”55dp” android:text=”Male” android:id=”@+id/radioButton” android:layout_gravity=”center_horizontal” android:checked=”false” android:textSize=”25dp” /> <RadioButton android:layout_width=”wrap_content” android:layout_height=”wrap_content” … Read more

tech