title: Recyclerview with radio group select only yes or no
body: <p>I have a recyclerview with two radio buttons in every row. One is for 'yes' and another for 'No'. I want to select only one radio button from each row at a time and get the value or the position of that radio button in an array list. In order to achieve single selection, I have enclosed these two radio buttons inside a Radio group. I need to set 'No' radio button in every row as active by default. Later, the user can select either 'Yes' or 'No' and the selected values should be stored in an ArrayList. How I achieve this.</p>
  
  <p>here is my adapter code.</p>
  
  <pre><code>public class MyHealthInfoAdapter extends RecyclerView.Adapter&lt;MyHealthInfoAdapter.MyHealthViewHolder&gt; {
  
  private Context context;
  private ArrayList&lt;DonorHealthStatusQuestionare&gt; listQuestions;
  private RadioButton lastCheckedRadioBtn = null;
  
  private ArrayList&lt;Integer&gt; listYes = new ArrayList&lt;&gt;();
  private ArrayList&lt;Integer&gt; listNo = new ArrayList&lt;&gt;();
  
  private FloatingActionButton floatingActionButton;
  
  
  public MyHealthInfoAdapter() {
  }
  
  public MyHealthInfoAdapter(Context context, ArrayList&lt;DonorHealthStatusQuestionare&gt; listQuestions) {
      this.context = context;
      this.listQuestions = listQuestions;
  }
  
  @Override
  public MyHealthViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rv_my_health_info, parent, false);
      return new MyHealthViewHolder(view);
  }
  
  @Override
  public void onBindViewHolder(final MyHealthViewHolder holder, final int position) {
  
      final DonorHealthStatusQuestionare donorHealthStatusQuestionare = listQuestions.get(position);
      holder.tvQuestion.setText(donorHealthStatusQuestionare.getQuestions());
  
  }
  
  @Override
  public int getItemCount() {
      return listQuestions.size();
  }
  
  public class MyHealthViewHolder extends RecyclerView.ViewHolder {
  
      CardView cvParent;
      TextView tvQuestion;
      RadioButton radioYes, radioNo;
      RadioGroup radioGroup;
  
      public MyHealthViewHolder(View itemView) {
          super(itemView);
          cvParent = itemView.findViewById(R.id.card_view_my_health_status_rv);
          tvQuestion = itemView.findViewById(R.id.tv_eligibility_question_my_info);
          radioYes = itemView.findViewById(R.id.radio_yes_my_health_info);
          radioNo = itemView.findViewById(R.id.radio_no_my_health_info);
  
          radioGroup = itemView.findViewById(R.id.my_health_status_check_group);
  
  
      }
  
  }
  
  
  }
  </code></pre>
  
  <p>And here is my recyclerview layout.</p>
  
  <pre><code>&lt;android.support.v7.widget.CardView
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/card_view_my_health_status_rv"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:layout_marginBottom="1dp"&gt;
  
  &lt;LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:baselineAligned="false"
      android:orientation="horizontal"
      android:padding="12dp"&gt;
  
      &lt;RelativeLayout
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_marginEnd="16dp"
          android:layout_marginRight="16dp"
          android:layout_weight="1"&gt;
  
          &lt;TextView
              android:id="@+id/tv_eligibility_question_my_info"
              android:layout_width="match_parent"
              android:layout_height="wrap_content" /&gt;
  
      &lt;/RelativeLayout&gt;
  
  
      &lt;RadioGroup
          android:orientation="horizontal"
          android:id="@+id/my_health_status_check_group"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_weight="0"&gt;
  
          &lt;RadioButton
              android:id="@+id/radio_yes_my_health_info"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginEnd="16dp"
              android:layout_marginRight="16dp"
              android:text="@string/yes" /&gt;
  
          &lt;RadioButton
              android:id="@+id/radio_no_my_health_info"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:text="@string/no" /&gt;
  
      &lt;/RadioGroup&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>