在投下反对票之前,请考虑一下我在各处搜索过的内容,但未找到解决方法,请提供帮助。
从上面的结构中,我想访问“结果”->“ examId”>“ total_marks”,“ marks_scored”中的值,但是我无法进入“结果”节点
我希望将值提供给recyclerview 这是我的适配器
public class MarksListAdapter extends RecyclerView.Adapter<MarksListAdapter.MyViewHolder> {
Context context;
ArrayList<MarksList> marksListArrayList;
public MarksListAdapter(Context c, ArrayList<MarksList> p) {
context = c;
marksListArrayList = p;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.marks_list, viewGroup, false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
myViewHolder.tvStudentName.setText(marksListArrayList.get(i).getName());
myViewHolder.tvOutOf_List.setText(marksListArrayList.get(i).getResults().getTotal_marks());
myViewHolder.etEnterMarks.setText(marksListArrayList.get(i).getResults().getMarks_scored());
POJO类
public class MarksList {
String name;
public MarksList() {
}
public MarksList(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
private Results Results;
public com.hitech.hitechacademy.POJO.Results getResults() {
return Results;
}
}
public class Results {
String marks_scored;
String total_marks;
public Results() {
}
public Results(String marks_scored, String total_marks) {
this.marks_scored = marks_scored;
this.total_marks = total_marks;
}
public String getMarks_scored() {
return marks_scored;
}
public void setMarks_scored(String marks_scored) {
this.marks_scored = marks_scored;
}
public String getTotal_marks() {
return total_marks;
}
public void setTotal_marks(String total_marks) {
this.total_marks = total_marks;
}
}
都是独立的Java类
这是recyclerview活动
DatabaseReference examRef = firebaseDatabase.getReference().child("Batches").child(batchNameValue);
examRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String examTitle;
String studentName;
specificStudent.clear();
resultsArrayList.clear();
for (DataSnapshot studentResult : dataSnapshot.getChildren()) {
examTitle = (String) studentResult.child("Results").child(examKeyValue).child("exam_name").getValue();
Log.d("TAG_Full", examTitle + "" + examFullName);
if (examTitle != null && examTitle.equals(examFullName)) {
MarksList marksList = studentResult.getValue(MarksList.class);
//studentName = (String) studentResult.child("name").getValue();
specificStudent.add(marksList);
Log.d("SpecificStudent", specificStudent.toString() + resultsArrayList.toString());
} else {
//code for 1 exam and no students
}
}
specificStudent.toString();
marksListAdapter = new MarksListAdapter(LoadedExam.this,specificStudent);
marksRecyclerView.setAdapter(marksListAdapter);
marksListAdapter.notifyDataSetChanged();
}
我没有收到任何错误,但只获取了学生的姓名。请帮助