MultiRowsRadioGroup icon indicating copy to clipboard operation
MultiRowsRadioGroup copied to clipboard

How to add these button programatically?

Open MustanserIqbal93 opened this issue 8 years ago • 2 comments

Hi, Can you tell me how i add these control by code. it is working using xml but not from.

Thanks.

MustanserIqbal93 avatar Jun 14 '17 17:06 MustanserIqbal93

Use like RadioGroup:

MultiRowsRadioGroup group = new MultiRowsRadioGroup(context);
...
group.addView(child);
...

linfaxin avatar Jun 15 '17 02:06 linfaxin

I have tried this already but it checks all the Radio buttons this is my code.

MultiRowsRadioGroup rg = Constants.CreateRadioGroup(CampaignFormData.this, questionDetail);

LinearLayout buttonsLayout = new LinearLayout(CampaignFormData.this);
                                    buttonsLayout.setLayoutParams(params);
                                    buttonsLayout.setPadding(10, 5, 10, 5);
                                    buttonsLayout.setOrientation(LinearLayout.HORIZONTAL);
                                    buttonsLayout.setWeightSum(2);
                                    rg.addView(buttonsLayout);
                                    for (int choices = 0; choices < questionDetail.getQuestionChoices().size(); choices++) {

                                        RadioButton radioButton = Constants.CreateRadioButton(CampaignFormData.this, questionDetail.getQuestionChoices().get(choices), questionDetail.getQuestionChoices().size());

                                        if (choices % 2 == 0 && choices != 0) {
                                            buttonsLayout = new LinearLayout(CampaignFormData.this);
                                            buttonsLayout.setLayoutParams(params);
                                            buttonsLayout.setPadding(10, 5, 10, 5);
                                            buttonsLayout.setOrientation(LinearLayout.HORIZONTAL);
                                            buttonsLayout.setWeightSum(2);
                                            rg.addView(buttonsLayout);
                                        }
                                        buttonsLayout.addView(radioButton);
                                    }



    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
    public static RadioButton CreateRadioButton(Context context, FormData.QuestionChoice questionChoice, int size) {

        RadioButton rb = new RadioButton(context);
            RadioGroup.LayoutParams params = new RadioGroup.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f);
            rb.setLayoutParams(params);
        rb.setTag(questionChoice.getChoiceId());
        rb.setButtonTintList(getTintColor(context));
        rb.setId(Integer.parseInt(questionChoice.getChoiceId()));
        rb.setText(questionChoice.getChoice());
        rb.setTextColor(getTintColor(context));
        return rb;
    }



    public static MultiRowsRadioGroup CreateRadioGroup(Context context, FormData.QuestionDetail questionDetail) {

        MultiRowsRadioGroup rg = new MultiRowsRadioGroup(context);
        rg.setOrientation(LinearLayout.VERTICAL);
        rg.setPadding(10, 10, 10, 10);
        rg.setId(Integer.parseInt(questionDetail.getQuestionId()));
        rg.setTag(questionDetail.getQuestionId());
        return rg;
    }

Can you check what is wrong with this code? Thanku

MustanserIqbal93 avatar Jun 15 '17 07:06 MustanserIqbal93