0
votes

This is my data from Firebase Console.

My data

I'm trying to create a database reference of the children inside the users UID to use them for Recycler Adapter.

DatabaseReference ref =FirebaseDatabase.getInstance().getReference().child("Offers").child(???)

1

1 Answers

0
votes

You need to retrieve the random id, to be able to use it inside the child() example:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference().child("Offers").push();
String pushKey = ref.getKey();

then when you want to retrieve the children you can do:

DatabaseReference ref =FirebaseDatabase.getInstance().getReference().child("Offers").child(pushKey);
ref.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
         for(DataSnapshot ds : dataSnapshot.getChildren()){
             String name = ds.child("Name").getValue(String.class);
           }

    }

    @Override
    public void onCancelled(FirebaseError firebaseError) {
    }
});