📌  相关文章
📜  计算数据在 firebase 数据库中出现的次数 - 无论代码示例

📅  最后修改于: 2022-03-11 15:00:06.099000             🧑  作者: Mango

代码示例1
databaseReference = FirebaseDatabase.getInstance().getReference().child("Attendance").child(istrustnumberavailable);
    databaseReference.limitToFirst(5);

    Query query = databaseReference.orderByChild("name").equalTo("prof");

    ChildEventListener removedListener = query.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            if (dataSnapshot.exists()){

              long  count=  dataSnapshot.getChildrenCount();


            }


        }

        @Override
        public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            if (dataSnapshot.exists()){

                long  count=  dataSnapshot.getChildrenCount();


            }


        }

        @Override
        public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {

            if (dataSnapshot.exists()){

                long  count=  dataSnapshot.getChildrenCount();


            }



        }

        @Override
        public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {


        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });