-1

Firebase database structure :

-Main

---item1: "Structure"

---item2: "good"

---item3: "something"

+users

KENdi
  • 7,576
  • 2
  • 16
  • 31
Shushant
  • 11
  • 3

1 Answers1

0

Please use this code:

DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference mainRef = rootRef.child("Main");
ValueEventListener eventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for(DataSnapshot ds : dataSnapshot.getChildren()) {
            String item = ds.getKey();
            Log.d("TAG", item);
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {}
};
mainRef.addListenerForSingleValueEvent(eventListener);

And your output will be:

item1
item2
item3
Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • 1
    While this will only **print** the keys, it will still **fetch** the values too. There is no way in the Firebase SDKs to fetch just the keys. Also see https://stackoverflow.com/questions/41590730/firebase-shallow-query-parameter-for-android – Frank van Puffelen Jul 06 '17 at 13:39
  • How can I print these outputs in a list view – Shushant Jul 06 '17 at 14:23
  • I recomand you using [FirebaseUI](https://github.com/firebase/FirebaseUI-Android). – Alex Mamo Jul 06 '17 at 14:25