数据成功添加到firebase中, 然而它只发送了recyclerView的3个数据。
基于什么chatGpt 由于屏幕上只有 3 个 recyclerView,这就是为什么只有 3 个成功检索
这是代码
public void submitButtonFunction(){
submitButton = findViewById(R.id.submitButton);
submitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(date!=null) {
DatabaseReference dateRef = rootRef.getReference()
.child("Subject")
.child(courseCode)
.child("attendance")
.child(date);
List<String> selectedCheckBoxes = new ArrayList<>();
boolean anyCheckBoxChecked = false;
Log.d("Date", date);
for (int i = 0; i < recyclerView.getChildCount(); i++) {
View view = recyclerView.getChildAt(i);
CheckBox attendCheckBox = view.findViewById(R.id.attendCheckBox);
CheckBox absentCheckBox = view.findViewById(R.id.absentCheckBox);
CheckBox excuseCheckBox = view.findViewById(R.id.excuseCheckBox);
if (attendCheckBox.isChecked()) {
selectedCheckBoxes.add("Attend");
anyCheckBoxChecked = true;
} else if (absentCheckBox.isChecked()) {
selectedCheckBoxes.add("Absent");
anyCheckBoxChecked = true;
} else if (excuseCheckBox.isChecked()) {
selectedCheckBoxes.add("Excuse");
anyCheckBoxChecked = true;
} else {
Toast.makeText(studentAttendance.this, "Please Check All the checkboxes", Toast.LENGTH_SHORT).show();
selectedCheckBoxes.add("Not Checked");
}
String tempNameMatric = list.get(i).getStudentMatricNo() + " " + list.get(i).getStudentName() ;
dateRef.child(tempNameMatric).setValue(selectedCheckBoxes.get(i))
.addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(studentAttendance.this, "Succesful submit attendance", Toast.LENGTH_SHORT).show();
}
});
}
}else{
Toast.makeText(studentAttendance.this, "Please Enter Date Of Attendance", Toast.LENGTH_SHORT).show();
}
}
});
}
我已经尝试过 -更改循环条件
i < list.size()
-基于chatGpt
for (int i = 0; i < list.size(); i++) {
subject currentSubject = list.get(i);
CheckBox attendCheckBox = recyclerView.findViewHolderForAdapterPosition(i)
.itemView.findViewById(R.id.attendCheckBox);
CheckBox absentCheckBox = recyclerView.findViewHolderForAdapterPosition(i)
.itemView.findViewById(R.id.absentCheckBox);
CheckBox excuseCheckBox = recyclerView.findViewHolderForAdapterPosition(i)
.itemView.findViewById(R.id.excuseCheckBox);
尝试安装
for (int i = 0; i < recyclerView.getChildCount(); i++) {
// all the logic was here
}
上面只会计算并返回当前附加到 RecyclerView 的子视图数量,这几乎是屏幕上的数量。
使用
for (int i = 0; i < recyclerView.getAdapter().getItemCount(); i++) {
// all of the code remains in here as you have
}
阅读更多相关内容recyclerview-getchildcount-is-returning- different-number-of-child-each