title: In cardview with radiogroup in list some radio buttons are already checked
body: <p>I had created cardview with radio group in android here i am making student attendence taker system ,i had already made backend part and student list is coming correctly and showing in cards but problem is at time of present, or absent marking of student , i had used radiogroup with 4 radio button in each card . But some radio buttons are already been checked and when i am scrolling then checked position of radio button is also changing .:-
  code for every single card is </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:card_view="http://schemas.android.com/apk/res-auto"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      card_view:cardCornerRadius="5dp"
  
      card_view:cardUseCompatPadding="true" &gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="5dp" &gt;
  
          &lt;TextView
              android:id="@+id/tvName"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_alignParentTop="true"
              android:text="name"
              android:textColor="@android:color/black"
              android:textSize="18sp" /&gt;
  
          &lt;TextView
              android:id="@+id/tvEmailId"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_below="@id/tvName"
              android:text="email"
              android:textColor="@android:color/black"
              android:textSize="18sp" /&gt;
  &lt;RadioGroup android:id="@+id/rg"
      android:layout_alignParentRight="true"
      android:layout_centerVertical="true"
  
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"&gt;
  
  
          &lt;RadioButton
              android:id="@+id/chkSelected"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentRight="true"
              android:layout_centerVertical="true"
              android:text="A"
              android:checked="false"&gt;
  
  
          &lt;/RadioButton&gt;
  
          &lt;RadioButton
              android:id="@+id/chkSelected2"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginRight="64dp"
              android:layout_marginEnd="64dp"
              android:layout_centerVertical="true"
              android:layout_toLeftOf="@+id/chkSelected"
              android:layout_toStartOf="@+id/chkSelected"
              android:text="P"
              android:checked="false"&gt;
  
  
          &lt;/RadioButton&gt;
  
  &lt;/RadioGroup&gt;
  
      &lt;/RelativeLayout&gt;
  
  &lt;/android.support.v7.widget.CardView&gt;
  </code></pre>
  
  <p>and code for checkboxsample.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"&gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:orientation="horizontal"
          android:gravity="center"
          android:layout_height="wrap_content"&gt;
  
          &lt;Button
              android:layout_width="wrap_content"
              android:text="Check All"
              android:layout_marginRight="7dip"
              android:id="@+id/btnCheckAll"
              android:layout_height="wrap_content"&gt;
          &lt;/Button&gt;
          &lt;Button
              android:layout_width="wrap_content"
              android:text="Clear All"
              android:id="@+id/btnClearAll"
              android:layout_height="wrap_content"&gt;
          &lt;/Button&gt;
      &lt;/LinearLayout&gt;
  
      &lt;ListView
          android:layout_width="fill_parent"
          android:id="@+id/lvCheckBox"
          android:fadingEdge="none"
          android:cacheColorHint="@null"
          android:layout_height="fill_parent"&gt;
      &lt;/ListView&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>code for activity_main.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;include
          android:id="@+id/toolbar"
          layout="@layout/toolbar" /&gt;
  
      &lt;android.support.v7.widget.RecyclerView
          android:id="@+id/my_recycler_view"
          android:layout_width="match_parent"
          android:layout_height="0dp"
          android:layout_margin="5dp"
          android:layout_weight="1"
          android:scrollbars="vertical" /&gt;
  
      &lt;Button
          android:id="@+id/btnShow"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_margin="5dp"
          android:text="Show Selected"
          android:background="#00796B" 
          android:textColor="@color/TextPrimaryColor"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>code for student.java</p>
  
  <pre><code>package com.example.administrator.cardviewcheckbok;
  
  import java.io.Serializable;
  
  public class Student implements Serializable {
  
      /**
       * 
       */
      private static final long serialVersionUID = 1L;
  
      private String name;
  
      private String emailId;
  
      private boolean isSelected;
  
      public Student() {
  
      }
  
      public Student(String name, String emailId) {
  
          this.name = name;
          this.emailId = emailId;
  
      }
  
      public Student(String name, String emailId, boolean isSelected) {
  
          this.name = name;
          this.emailId = emailId;
          this.isSelected = isSelected;
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getEmailId() {
          return emailId;
      }
  
      public void setEmailId(String emailId) {
          this.emailId = emailId;
      }
  
      public boolean isSelected() {
          return isSelected;
      }
  
      public void setSelected(boolean isSelected) {
          this.isSelected = isSelected;
      }
  
  }
  </code></pre>
  
  <p>code for cardviewdataadapter.java</p>
  
  <pre><code>package com.example.administrator.cardviewcheckbok;
  
  import java.util.List;
  
  import android.support.v7.widget.RecyclerView;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  
  import android.view.ViewGroup;
  import android.widget.CheckBox;
  import android.widget.CompoundButton;
  import android.widget.RadioButton;
  import android.widget.RadioGroup;
  import android.widget.TextView;
  import android.widget.Toast;
  import android.widget.CompoundButton.OnCheckedChangeListener;
  
  public class CardViewDataAdapter extends
          RecyclerView.Adapter&lt;CardViewDataAdapter.ViewHolder&gt; {
  
      private List&lt;Student&gt; stList;
  
      public CardViewDataAdapter(List&lt;Student&gt; students) {
          this.stList = students;
  
      }
  
      // Create new views
      @Override
      public ViewHolder onCreateViewHolder(ViewGroup parent,
              int viewType) {
          // create a new view
          View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(
                  R.layout.cardview_row, null);
  
          // create ViewHolder
  
          ViewHolder viewHolder = new ViewHolder(itemLayoutView);
  
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(ViewHolder viewHolder, int position) {
  
          final int pos = position;
  
          viewHolder.tvName.setText(stList.get(position).getName());
  
          viewHolder.tvEmailId.setText(stList.get(position).getEmailId());
  
          viewHolder.chkSelected.setSelected(stList.get(position).isSelected());
  
          viewHolder.chkSelected.setTag(stList.get(position));
  ////new checkselected2
  
          viewHolder.chkSelected2.setSelected(stList.get(position).isSelected());
  
          viewHolder.chkSelected2.setTag(stList.get(position));
  
  viewHolder.checkrgg.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          RadioGroup rgg=(RadioGroup)v;
  int selbutid=rgg.getCheckedRadioButtonId();
  
      RadioButton rb= (RadioButton) rgg.getChildAt(selbutid);
  Toast.makeText(v.getContext(),""+rb.getText()+"",Toast.LENGTH_LONG).show();
  
      }
  });
  
          viewHolder.chkSelected.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  RadioButton cb = (RadioButton) v;
  
                  Student contact = (Student) cb.getTag();
  
                  contact.setSelected(cb.isSelected());
                  stList.get(pos).setSelected(cb.isSelected());
  
      /*          Toast.makeText(
                          v.getContext(),
                          "Clicked on Checkbox: " + "" + pos + cb + " is "
                                  + cb.isSelected(), Toast.LENGTH_LONG).show();
      */
                      }
  
              });
  
  
          viewHolder.chkSelected2.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  RadioButton cb = (RadioButton) v;
  
                  Student contact = (Student) cb.getTag();
  
                  contact.setSelected(cb.isSelected());
                  stList.get(pos).setSelected(cb.isSelected());
  /*
                  Toast.makeText(
                          v.getContext(),
                          "2222222Clicked on Checkbox: "+""+pos +cb + " is "
                                  + cb.isSelected(), Toast.LENGTH_LONG).show();
                  */
                      }
          });
  
  
  
      }
  
      // Return the size arraylist
      @Override
      public int getItemCount() {
          return stList.size();
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
  
          private final RadioGroup checkrgg;
          public TextView tvName;
          public TextView tvEmailId;
  
          public RadioButton chkSelected,chkSelected2;
  
          public Student singlestudent;
  
          public ViewHolder(View itemLayoutView) {
              super(itemLayoutView);
  
              tvName = (TextView) itemLayoutView.findViewById(R.id.tvName);
  
              tvEmailId = (TextView) itemLayoutView.findViewById(R.id.tvEmailId);
              chkSelected = (RadioButton) itemLayoutView
                      .findViewById(R.id.chkSelected);
  
              ///here putted code
              chkSelected2 = (RadioButton) itemLayoutView
                      .findViewById(R.id.chkSelected2);
  ////
              checkrgg=(RadioGroup)itemLayoutView.findViewById(R.id.rg);
  
          }
  
      }
  
      // method to access in activity after updating selection
      public List&lt;Student&gt; getStudentist() {
          return stList;
      }
  
  }
  </code></pre>
  
  <p>code for cardviewactivity.java</p>
  
  <pre><code>package com.example.administrator.cardviewcheckbok;
  
  import java.util.ArrayList;
  import java.util.List;
  import android.os.Bundle;
  import android.support.v7.app.ActionBarActivity;
  import android.support.v7.widget.LinearLayoutManager;
  import android.support.v7.widget.RecyclerView;
  import android.support.v7.widget.Toolbar;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.widget.Button;
  import android.widget.Toast;
  
  public class CardViewActivity extends ActionBarActivity {
  
      private Toolbar toolbar;
  
      private RecyclerView mRecyclerView;
      private RecyclerView.Adapter mAdapter;
      private RecyclerView.LayoutManager mLayoutManager;
  
      private List&lt;Student&gt; studentList;
  
      private Button btnSelection;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          toolbar = (Toolbar) findViewById(R.id.toolbar);
          btnSelection = (Button) findViewById(R.id.btnShow);
  
          studentList = new ArrayList&lt;Student&gt;();
  
          for (int i = 1; i &lt;= 15; i++) {
              Student st = new Student("Student " + i, "androidstudent" + i
                      + "@gmail.com", false);
  
              studentList.add(st);
          }
  
          if (toolbar != null) {
              setSupportActionBar(toolbar);
              getSupportActionBar().setTitle("Android Students");
  
          }
  
          mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
  
          // use this setting to improve performance if you know that changes
          // in content do not change the layout size of the RecyclerView
          mRecyclerView.setHasFixedSize(true);
  
          // use a linear layout manager
          mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
  
          // create an Object for Adapter
          mAdapter = new CardViewDataAdapter(studentList);
  
          // set the adapter object to the Recyclerview
          mRecyclerView.setAdapter(mAdapter);
  
          btnSelection.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  String data = "";
                  List&lt;Student&gt; stList = ((CardViewDataAdapter) mAdapter)
                          .getStudentist();
  
                  for (int i = 0; i &lt; stList.size(); i++) {
                      Student singleStudent = stList.get(i);
                      if (singleStudent.isSelected() == true) {
  
                          data = data + "\n" + singleStudent.getName().toString();
                          /*
                           * Toast.makeText( CardViewActivity.this, " " +
                           * singleStudent.getName() + " " +
                           * singleStudent.getEmailId() + " " +
                           * singleStudent.isSelected(),
                           * Toast.LENGTH_SHORT).show();
                           */
  
                  ////
                                                  }
  
                  }
  
                  Toast.makeText(CardViewActivity.this,
                          "Selected Students: \n" + data, Toast.LENGTH_LONG)
                          .show();
              }
          });
  
      }
  
  }
  </code></pre>
  
  <p>Please these is big problematic issue . Actually if we do it by using list then also same error comes , so want help from community to please give some suggestion on these issue of  . "card view with radio group in list"</p>