2016-11-21 27 views
1

動的に、私はrecycleviewで1つの質問の下に複数のオプションを追加しました。今、ユーザーが以下の画像では、各questions.Look内のオプションを選択することができ、 enter image description hererecyclerviewで選択したラジオボタンの値を取得する方法は?

Recyclerview Adapterクラスは、

@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); 

     } 
    } 

ユーザーがRadioButtonを選択した場合、私は、各質問のすべてにチェック値を取得したいですRadioGroupの内部にあります。

答えて

1

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

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

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

+0

コードを使用して簡単に説明できますか? – pb123

+0

ねえ。私はあなたがそれまでにそれを働かせなければ、今夜のコードであなたに答えを与えることができます。私は私の投稿を編集します – bogdanN

+0

私は各質問(名前とID)の下でオプションを得ることができません。コードで私を詳しく教えてもらえますか?前もって感謝します!!!! – pb123

関連する問題