Is it possible to have a radio group with radio buttons in their own layouts? Every radio button has to be on a row that contains text and an image. I wouldn't use a list view because I only have 2 rows.
In Android, RadioButton are mainly used together in a RadioGroup. In RadioGroup checking the one radio button out of several radio button added in it will automatically unchecked all the others. It means at one time we can checked only one radio button from a group of radio buttons which belong to same radio group.
Radio buttons allow only one choice within a group of buttons. Each radio button within a group should have the same name. You can create more than one group of radio buttons by using different names.
Vertical positioning of radio buttons is safer. Try to lay out your lists vertically, with one choice per line. If you still need a horizontal layout with multiple options per line, make sure to space the buttons and labels so that it's absolutely clear which choice goes with which label.
Only one radio button in a given group can be selected at the same time. Radio buttons are typically rendered as small circles, which are filled or highlighted when selected.
Here is the way to do it:
Create a separate RadioGroup
on each RadioButton
in the XML layout file. For example:
<RadioGroup
android:id="@+id/rdoFooWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rdoFoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
<RadioGroup
android:id="@+id/rdoBooWrapper"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/rdoBoo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
Now, inside the java source code, do something like this:
rdoFooWrapper = (RadioGroup) findViewById(R.id.rdoFooWrapper);
rdoFoo = (RadioButton) findViewById(R.id.rdoFoo);
rdoBooWrapper = (RadioGroup) findViewById(R.id.rdoBooWrapper);
rdoBoo = (RadioButton) findViewById(R.id.rdoBoo);
rdoFoo.setOnCheckedChangeListener(this); // implement OnCheckedChangeListener to the current class
rdoBoo.setOnCheckedChangeListener(this);
// ...
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
rdoFooWrapper.clearCheck();
rdoBooWrapper.clearCheck();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With