简体   繁体   中英

How can I retrieve the value from Firebase Realtime database?

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?

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);
 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:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM