The problem is that the snapshot that the child_added
event gives is the new child data. So getChildrenCount()
counts how many properties (children) a new child has (and has 3).
To do what you want, you must add a ValueEventListener
event as follows:
queryRef.addValueEventListener(new ValueEventListener() { public void onCancelled(FirebaseError arg0) { } public void onDataChanged(DataSnapshot arg0, String arg1) { System.out.println("Size "+arg0.getChildrenCount()); } });
This should return all children in the queryRef
place every time the value changes (for example, a new child).
Tell me if this works, as I cannot try it myself.
source share