Getting child count in Firebase

前端 未结 2 1590
生来不讨喜
生来不讨喜 2021-01-22 01:55

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 <

2条回答
  •  北恋
    北恋 (楼主)
    2021-01-22 02:12

    The problem was this line:

    databaseReference.child("PrinterView").child(uni).child(phone).orderByChild("done").equalTo("No").addValueEventListener(new ValueEventListener() 
    

    The variable "uni" and "phone" was also provided by a firebase Query E.G It was to get the University and phone number of the current user so I could not just put a static string there.

        databaseReference.child("Users").child(mAuth.getCurrentUser().getUid()).child("Phone").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                phone = dataSnapshot.getValue().toString();
                // Toast.makeText(getActivity(), phone, Toast.LENGTH_LONG).show();
                setPendingList();
            }
    
            @Override
            public void onCancelled(DatabaseError databaseError) {
    
            }
        });
    

    So the issue was that, if the network connection was slow or if the queries were not done yet, those two variables would be empty thereby making the dataSnapshot empty. I will have to sort that out by only allowing that to be queried when the rest are sure to be done. :)

提交回复
热议问题