Home > Net >  How can I retrieve the value from Firebase Realtime database?
How can I retrieve the value from Firebase Realtime database?

Time:12-02

I have this structure and i want to retrieve all the values from that authentication ID's how can I get all those details from (Users/Drivers) in one go?

CodePudding user response:

Same as my answer for previously asked: Error when i try to update data from firebase

I would suggest adding aditional child lets name is id for example and the value of this child would be same as the value of firebase push id.

let's get with Editing:

pass a String textId variable for adapter so that when you click on edit from the menu it would set the textId value to be the push id from the firebase, which would be the child that have data you need to edit.

now use the child(textId).updateChildren(//Your hashmap);

and it would work.

Example of my usage:

String textId= productRef.child(UID).child("images").push().getKey();


HashMap<String ,Object> hashMap = new HashMap<>();
        hashMap.put("image", url);
        hashMap.put("id", textId);

 productRef.child(UID).child("images").child(textId).updateChildren(hashMap);

CodePudding user response:

 FirebaseDatabase.getInstance().getReference().child("Users").child("Drivers").addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(@NonNull DataSnapshot snapshot) {
                    for(DataSnapshot snapshot1:snapshot.getChildren()){
                        MyModel myModel=snapshot1.getValue(MyModel.class);
                        list.add(myModel);
                        AdapterSecond  second = new AdapterSecond(list,MainActivity.this);
                        r1.setAdapter(second);
                        r1.setLayoutManager(new LinearLayoutManager(MainActivity.this));
                    }
                }

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

                }
            });

I just resolved my error by the above code, I hope it helps somebody :)

  • Related