Please how do I simply get the child count from a firebase Query. For example Let's say I use a database query with 10 children, how do I get that value because I tried using onChildChanged and getting the value from the snapshot, but it does not work well. This is because at first it will get the number, then it will query again because it has to continuously sync, but because there is not actual child change at the second query it return a value if zero which will replace the original correct value. :/
databaseReference.child("PrinterView").child(uni).child(phone).orderByChild("done").equalTo("No").addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
Toast.makeText(getActivity(),"Number:"+String.valueOf(dataSnapshot.getChildrenCount()),Toast.LENGTH_LONG).show();
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Both don't work
databaseReference.child("PrinterView").child(uni).child(phone).orderByChild("done").equalTo("No").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Toast.makeText(getActivity(),"Number:"+String.valueOf(dataSnapshot.getChildrenCount()),Toast.LENGTH_LONG).show();
Vendor_view_Home_fragment.printIndicator.setText(String.valueOf(dataSnapshot.getChildrenCount()));
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});