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,
It seems that you are making a new RadioGroup for every RadioButton. 
You should add every new RadioButton to the same RadioGroup. The RadioGroup will then make sure only one RadioButton can be selected at the time.
 @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        Log.d(TAG, "onCheckedChanged  " + buttonView.getId());
        mRadioGroup.clearCheck();
        if (isChecked) {
            mRadioGroup.check(buttonView.getId());
        }
    }
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