I am making an attendance app and I need to count the particular student attendance from the Firebase. I need to count the number of "prof" occurrence and I am new to this.
DatabaseReference attendance = FirebaseDatabase.getInstance().getReference("Attendance");
attendance.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
totaldays++; // total class days
if(snapshot.child("name").getValue(String.class).equals("prof")){
//count no of days present
}
Log.e(snapshot.getKey(), snapshot.getChildrenCount() + "");
}
Log.e(TAG, totaldays + "");
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {}
});
But the result is showing null
value.