我在 RecyclerView 项目中遇到 RadioButton 问题。根据“类型”,我更改了选中的 RadioButton。但是在加载所有数据之后,当我单击未选中的单选按钮时,它会被选中。但是在滚动我刚刚单击的已选中单选按钮后,该按钮未被选中。我想要检查我刚刚单击的按钮。但它不会被检查。我怎样才能得到我想要的?谁能帮帮我吗!!!!!!!
这是我的适配器类:
public class AttendanceAdapterLocal extends RecyclerView.Adapter<AttendanceAdapterLocal.ViewHolder>{
private ArrayList<StudentAttendance> attendanceArrayList;
private Context context;
public AttendanceAdapterLocal(ArrayList<StudentAttendance> 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") > 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();
}
}
});
猛跑小猪
回首忆惘然
慕斯709654
相关分类