2016-11-21 58 views
1

動態地,我在recycleview的一個問題下添加了多個選項。現在,用戶可以選擇在下面的圖像的每個questions.Look內的一個選項, enter image description here如何在回收站查看所選單選按鈕的值?

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

根據您想要使用信息的時間有兩種方法。

如果您想等待用戶檢查所有問題,然後獲取值(例如Send Answers按鈕或類似的東西),則可以使用RadioGroup對象中的getCheckedRadioButtonId()。

如果您想立即使用信息(用戶選擇它),您可以在收音機組對象上的收音機組對象上添加一個監聽器:setOnCheckedChangeListener()。

+0

可以請您使用代碼簡單解釋一下嗎? – pb123

+0

嘿。如果到那時你還沒有得到它,我可以在今晚給你一個代碼的答案。我將編輯我的文章 – bogdanN

+0

我無法獲得每個問題(姓名和ID)下的選項。你能用代碼來詳細說明我嗎?提前致謝!!!! – pb123