title: RadioButton checked sate automatically changes on scrolling event of RecyclerView
body: <p>I am facing problem with my RadioButton in RecyclerView item. According to the 'type' I changes the checked RadioButton. But after all data loaded, then when I click the non checked radio button it's get checked. But after scrolling the checked radio button which I just clicked that goes unchecked. I want the button which I just clicked to be checked. But it is doesn't stays checked. How do I get what I want? Can anyone please help me!!!!!!!</p>
  
  <p><strong>This is my Adapter Class:</strong></p>
  
  <pre><code>public class AttendanceAdapterLocal extends  RecyclerView.Adapter&lt;AttendanceAdapterLocal.ViewHolder&gt;{
      private ArrayList&lt;StudentAttendance&gt; attendanceArrayList;
      private Context context;
  
      public AttendanceAdapterLocal(ArrayList&lt;StudentAttendance&gt; attendanceArrayList) {
          this.attendanceArrayList = attendanceArrayList;
      }
  
      @NonNull
      @Override
      public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
          View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item_mark_attendance, viewGroup, false);
          context = viewGroup.getContext();
          return new ViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull final ViewHolder viewHolder, int i) {
          final String type = attendanceArrayList.get(i).getType();
          final String id = attendanceArrayList.get(i).getId();
          final String name = attendanceArrayList.get(i).getName();
          final String roll = attendanceArrayList.get(i).getRoll();
          viewHolder.setData(name, roll, type, id);
  
          final DatabaseHelper databaseHelper = new DatabaseHelper(context);
          final User user = new AccessStorage(context).getUserDetails();
          final String userId = user.getUserId();
          viewHolder.radioPresent.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (databaseHelper.updateStudentAttendanceData(id, userId, "P", "0") &gt; 0) {
                      Toast.makeText(context, "Marked successfully.", Toast.LENGTH_LONG).show();
                      viewHolder.radioPresent.setChecked(true);
                  } else {
                      Toast.makeText(context, "Unable to mark attendance.", Toast.LENGTH_LONG).show();
                  }
              }
          });
          viewHolder.radioAbsent.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (databaseHelper.updateStudentAttendanceData(id, userId, "A", "0") &gt; 0) {
                      Toast.makeText(context, "Marked successfully.", Toast.LENGTH_LONG).show();
                      viewHolder.radioAbsent.setChecked(true);
                  } else {
                      Toast.makeText(context, "Unable to mark attendance.", Toast.LENGTH_LONG).show();
                  }
              }
          });
          viewHolder.radioNone.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (databaseHelper.updateStudentAttendanceData(id, userId, "NA", "0") &gt; 0) {
                      Toast.makeText(context, "Marked successfully.", Toast.LENGTH_LONG).show();
                      viewHolder.radioNone.setChecked(true);
                  } else {
                      Toast.makeText(context, "Unable to mark attendance.", Toast.LENGTH_LONG).show();
                  }
              }
          });
      }
  
      @Override
      public int getItemCount() {
          return attendanceArrayList.size();
      }
  
      @Override
      public int getItemViewType(int position) {
          return position;
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          // Widgets
          private TextView textName;
          private RadioGroup radioGroup;
          private RadioButton radioPresent, radioAbsent, radioNone;
          // Vars
          private View view;
          public ViewHolder(@NonNull View itemView) {
              super(itemView);
              view = itemView;
  
              textName = view.findViewById(R.id.textName);
              radioGroup = view.findViewById(R.id.radioGroup);
              radioPresent = view.findViewById(R.id.radioPresent);
              radioAbsent = view.findViewById(R.id.radioAbsent);
              radioNone = view.findViewById(R.id.radioNone);
          }
  
          private void setData(String name, String roll, final String type, final String id) {
              textName.setText(roll + ". " + name);
  
              if (type.equals("P")) {
                  radioPresent.setChecked(true);
              } else if(type.equals("A")) {
                  radioAbsent.setChecked(true);
              }else if(type.equals("NA")) {
                  radioNone.setChecked(true);
              }
          }
      }
  }
  </code></pre>