I was wondering if is possible to group each single RadioButton
in a unique RadioGroup
maintaining the same structure. My structure look like this:
As you can see, now each RadioButton
is a child of different LinearLayout
. I tried using the structure below, but it doesn't work:
To group RadioButton controls as a set to function independently of other sets. Drag a GroupBox or Panel control from the Windows Forms tab on the Toolbox onto the form. Draw RadioButton controls on the GroupBox or Panel control.
To create each radio button option, create a RadioButton in your layout. However, because radio buttons are mutually exclusive, you must group them together inside a RadioGroup .
List<String> list = new ArrayList<String>(); list. add("one"); list. add("two"); list. add("three"); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.
Yes, there is a way. Drag a radio list widget to your screen, go to the Properties tab and select 'Orientation' -> Horizontal.
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 must implement radio buttons on your own.
This really isn't too hard. In your onCreate(), set your RadioButtons with their own onClick() so that when they are activated, they setChecked(true) and do the opposite for the other buttons. For example:
class FooActivity { RadioButton m_one, m_two, m_three; @Override protected void onCreate(Bundle savedInstanceState) { ... m_one = (RadioButton) findViewById(R.id.first_radio_button); m_two = (RadioButton) findViewById(R.id.second_radio_button); m_three = (RadioButton) findViewById(R.id.third_radio_button); m_one.setOnClickListener(new OnClickListener() { public void onClick(View v) { m_one.setChecked(true); m_two.setChecked(false); m_three.setChecked(false); } }); m_two.setOnClickListener(new OnClickListener() { public void onClick(View v) { m_one.setChecked(false); m_two.setChecked(true); m_three.setChecked(false); } }); m_three.setOnClickListener(new OnClickListener() { public void onClick(View v) { m_one.setChecked(false); m_two.setChecked(false); m_three.setChecked(true); } }); ... } // onCreate() }
Yeah, I know--way old-school. But it works. Good luck!
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