Recover the amount of children who have a knot

Asked

Viewed 74 times

1

How do I recover the amount of children you have in a knot?

I already have the right path, I just need to know how to count the children of this knot.

private DatabaseReference qtdeFilRef;    
qtdeFilhosRef.child("primeiroNo").child("segundoNo");

Does anyone know how to get the kids back from "second"?

1 answer

0


Your question has been answered.

https://stackoverflow.com/questions/48645172/how-to-get-count-of-nested-nodes-of-a-parent-node-in-firebase

I tested here and this code below was the one that best served me.

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference yourRef = rootRef.child("Authenticated-Users");
ValueEventListener eventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        int count = 0;
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            count = count + 1;
        }
        Log.d("TAG", count + "");
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {}
};
yourRef.addListenerForSingleValueEvent(eventListener);
  • There is another similar topic, which a firebase member answered. And warned that if there are many queries will overload the memory and processing time. https://stackoverflow.com/questions/15148803/in-firebase-is-there-a-way-to-get-the-number-of-children-of-a-node-without-load

Browser other questions tagged

You are not signed in. Login or sign up in order to post.