1

Dynamically, i have added multiple options under one question in recycleview. Now a user can select one option inside each questions.Look at the below image, enter image description here

Recyclerview Adapter class is,

 @Override
    public void onBindViewHolder(final MyViewHolder holder,int position) {
        final PollQstWithAns poll = dataList.get(position);

        holder.txt_poll_question.setText(poll.getPollQstName());

        for (int i = 0; i < poll.getOptionList().size(); i++) {
            final PollsData mPollsOptionsList = poll.getOptionList().get(i);

            final RadioButton rb = new RadioButton(context);
            rb.setText(mPollsOptionsList.getAns1());
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

                ColorStateList colorStateList = new ColorStateList(
                        new int[][]{

                                new int[]{-android.R.attr.state_enabled},
                                new int[]{android.R.attr.state_enabled}
                        },
                        new int[]{

                                Color.DKGRAY
                                , ContextCompat.getColor(context, R.color.colorPrimary)

                        }
                );
                rb.setButtonTintList(colorStateList);
                rb.invalidate();
                rb.setTextColor(ContextCompat.getColor(context, R.color.gray));
            }

            holder.optionRadioGroup.addView(rb);

        }
    }

I want to get all checked values from each questions, if user select the RadioButton inside the RadioGroup.

4

1 に答える 1

1

情報をいつ使用するかによって、2 つの方法があります。

ユーザーがすべての質問をチェックしてから値を取得するのを待ちたい場合 ([回答を送信] ボタンなど)、RadioGroup オブジェクトから getCheckedRadioButtonId() を使用できます。

情報をすぐに (ユーザーが選択したときに) 使用したい場合は、ラジオ グループ オブジェクトにリスナーを追加できます: ラジオ グループ オブジェクトに setOnCheckedChangeListener() 。

于 2016-11-21T14:22:49.937 に答える