I am designing customize form programmatically where user can put a question and can add multiple options using radio buttons. I have taken RadioGroup and i am adding radio buttons in it. But while selecting i want only one radio button get selected at a time. How to implement it programmatically. Please help me..
Here is my code
final RadioGroup radioGroup = new RadioGroup(getApplicationContext());
radioGroup.setId(1);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
RadioButton radioButtonView = new RadioButton(getApplicationContext());
radioButtonView.setId(i++);
radioButtonView.setText(addnew);
radioGroup.addView(radioButtonView, p);
loption.addView(radioGroup, p);
Thanks in advance,
RadioGroup
for everyRadioButton
? If all theRadioButton
s go into the sameRadioGroup
, you should get the behaviour you are looking for? Or are the code snippet from multiple places in your code? – Macmacabrei
anyway? are you using this whole code inside a for loop? – JiffyRadioGroup
of all the otherRadioButton
s and when you want to add a newRadioButton
, simply add it to thatRadioGroup
– Macmacabre