Warm tip: This article is reproduced from serverfault.com, please click

firebase getting exact childs from database

发布于 2020-11-27 19:18:23

i have problem to get exact childs from database and add it to the list of "teams". is that possible? i can't find proper way to solve this problem. please help me. image of my actual database structure i want to get only values of "2" and "3", just list of all teams without members. As a result of my solution im getting all elements from all children. i have tried sth like this:

mDatabase.child("teams").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                teamList.clear();
                for(DataSnapshot snapshot : dataSnapshot.getChildren()){
                    teamList.add(snapshot.getValue().toString());
                }
            }

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

            }
        }); 

Questioner
Bartosz Ocimek
Viewed
0
Taha Malik 2020-11-28 10:18:45

Use this

    mDatabase.child("teams").addValueEventListener(new ValueEventListener() {
           
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            teamList.clear();
            for(DataSnapshot snapshot : dataSnapshot.getChildren()){
                teamList.add(snapshot.getKey());
            }
        }
    
        @Override
        public void onCancelled(@NonNull DatabaseError error) {
    
        }
    });