我正在尝试从使用Firebase查询的子项列表中检索但是失败。我的代码。我的logcat每次都得到0,这意味着datasnapshot.getchildren什么都不返回。如何修复它?我分享我的数据库截图。
Query queryRef = databaseReference.child("Class").orderByChild("name").equalTo(contactofSA.getName());
queryRef.getRef().child("Student").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
final ArrayList<student> studentListFromServer=new ArrayList<student>();
if (dataSnapshot.getChildrenCount()==0){
Log.d("GK","0");
}
for(DataSnapshot StudentData:dataSnapshot.getChildren()){
student student=new student();
student=StudentData.getValue(student.class);
studentListFromServer.add(student);
}
studentActivity.studentList=new ArrayList<>();
studentActivity.studentList=studentListFromServer;
studentListAdapter.addAll(studentList);
studentItems.setAdapter(studentListAdapter);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});