title: Getting previous RadioButton value from RadioGroup inside a RecyclerView
body: <p><a href="https://i.stack.imgur.com/Ir6vJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ir6vJ.png" alt="Recyclerview screenshot"></a></p>
  
  <p>In the above value when I check the option "salt" it gives me the value of same position from the above item. So in this case it gives me "CH6"</p>
  
  <p>Like this when i check "Water" it gives me "CH4".</p>
  
  <p>So here is my <code>RecyclerView</code>,</p>
  
  <pre><code>  public class QuestionsAdapter extends 
  
      RecyclerView.Adapter&lt;QuestionsAdapter.ViewHolder&gt; {
  
              List&lt;String&gt; names = new ArrayList&lt;&gt;();
              Context c;
              String username;
              Map&lt;String,Object&gt; map = new HashMap&lt;&gt;();
              ArrayList&lt;QuestionData&gt; questions = new ArrayList&lt;&gt;();
  
  
  
              public QuestionsAdapter(Context c) {
                  this.c = c;
              }
  
              public void updateQuestion(ArrayList&lt;QuestionData&gt; data){
                  this.questions = data;
                  notifyDataSetChanged();
              }
              public class ViewHolder extends RecyclerView.ViewHolder {
                  TextView q;
                  RadioButton r1;
                  RadioButton r2;
                  RadioButton r3;
                  RadioButton r4;
                  RadioGroup rg;
  
                  public ViewHolder(View itemView) {
                      super (itemView);
                      rg = (RadioGroup)itemView.findViewById(R.id.RGroup);
                      q = (TextView)itemView.findViewById(R.id.question);
                      r1 = (RadioButton)itemView.findViewById(R.id.no1);
                      r2 = (RadioButton)itemView.findViewById(R.id.no2);
                      r3 = (RadioButton)itemView.findViewById(R.id.no3);
                      r4 = (RadioButton)itemView.findViewById(R.id.no4);
  
  
                  }
              }
  
  
              @Override
              public QuestionsAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
                  View v = LayoutInflater.from (parent.getContext ()).inflate (R.layout.qnalayout, parent, false);
                  return new ViewHolder(v);
  
  
  
              }
  
              @Override
              public void onBindViewHolder(final ViewHolder holder, int position) {
                  final QuestionData qholder =  questions.get(position);
  
                  String question= qholder.getQuestion();
                  final String qid = qholder.getId();
  
                  final ArrayList&lt;String&gt; options = new ArrayList&lt;&gt;();
                  options.add(qholder.getO1());
                  options.add(qholder.getO2());
                  options.add(qholder.getO3());
                  options.add(qholder.getO4());
                  Collections.shuffle(options);
                  final String o1 = options.get(0);
                  String o2 = options.get(1);
                  String o3 = options.get(2);
                  String o4 =  options.get(3);
                  final String[] answer = new String[1];
                  holder.q.setText(question);
                  holder.r1.setText(o1);
                  holder.r2.setText(o2);
                  holder.r3.setText(o3);
                  holder.r4.setText(o4);
                  holder.rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                      @Override
                      public void onCheckedChanged(RadioGroup group, @IdRes int checkedId) {
                          switch (checkedId){
                              case R.id.no1:
                                  Toast.makeText(c, holder.r1.getText().toString(), Toast.LENGTH_SHORT).show();
                                  break;
                              case R.id.no2:
                                  Toast.makeText(c, holder.r2.getText().toString(), Toast.LENGTH_SHORT).show();
  
                                  break;
                              case R.id.no3:
                                  Toast.makeText(c, holder.r3.getText().toString(), Toast.LENGTH_SHORT).show();
  
                                  break;
                              case R.id.no4:
                                  Toast.makeText(c, holder.r4.getText().toString(), Toast.LENGTH_SHORT).show();
  
                                  break;
                          }
                          RadioButton checked = (RadioButton)findViewById(checkedId);
                          answer[0] = checked.getText().toString();
                          Toast.makeText(c, checked.getText().toString(), Toast.LENGTH_SHORT).show();
                          map.put(qid,answer[0]);
                          System.out.println(map);
                      }
                  });
  
              }
  
  
              @Override
              public int getItemCount() {
                  if (questions!=null){
                      return questions.size();
  
                  }else {
                      return 0;
                  }
              }
  
          }
  </code></pre>
  
  <p>Thanks in advance!</p>