Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

android firebase - get childrens count

Here is my Firebase data

{
"ques": {
"Chemistry": {},
"Countries": {},
"Film": {},
"Geography": {},
"General Knowledge": {},
"Information Technology": {},
"Physics": {},
"Sports": {},
"Technology": {
"-Ki0y2ojhgAkDKVFostV": {},
"-Ki0ySAkiILNo2WSM7EO": {},
"-Ki1-8R-5gfHJGl9bDYC": {},
"-Ki1-fP2HlW0ejzVOGnD": {},
"-Ki1-vihF3xgP81UPT5t": {},
"-Ki10DSBPWIK0SAv5v8V": {},
"-Ki11-pLXVWZlv0XbKpp": {},
"-Ki11al-z6_MDBdpLGh7": {},
"-Ki11pxZvjvIl68UhVRc": {},
"-Ki124jOsYpy9bWpc7Yo": {},
"-Ki12oDiad-7X6UBTtBv": {},
"-Ki133GHJeys-J0vtdI9": {},
"-Ki13Iq62Ly_tx4tcxKa": {},
"-Ki13e4pp1Xnq7tnYa4N": {},
"-Ki142gU6ZHRkE34r0u3": {},
"-Ki14GswYf_lEji5a2PX": {},
"-Ki14WZpH5w5jnB4mZF1": {},
"-Ki14tX__g6VdmHJHi-g": {},
"-Ki15JghcU73RtW5zacV": {},
"-Ki15c91cOoRoR7h5aTL": {}
}
}
}

I want to count the number of keys available under Technology When I use the below code , gets count = 7 , but there is 20 keys available under Technology

Query countQuery = countRef.child("ques").child("Technology");
countQuery.addChildEventListener(new ChildEventListener() {
            @Override
            public void onChildAdded(DataSnapshot dataSnapshot, String s) {


                questionCount = (int) dataSnapshot.getChildrenCount();
                tQuestionNoShow.setText(""+questionCount);

            }

            @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) {

            }
        });

So.. How to implement it??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...