简体   繁体   中英

Get Value From Child in Firebase to Android Studio

数据库结构

In the picture is my database, so I want to retrieve the value of latitude and longitude from my databasem but the child name is named from random time based on the time when the data uploaded.

How can I get the value of latitude and longitude when I don't know what time that the child used because it's random time?

You want to fetch all data or any specific data?

EDIT:

        FirebaseDatabase.getInstance().getReference().child("History").child("Saturday").addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                for(DataSnapshot snapshot : dataSnapshot.getChildren()){
                    String lat = snapshot.child("Latitude").getValue().toString();
                    String longi = snapshot.child("Longitude").getValue().toString();

                    //OR you can typecast the entire snapshot object into your model class
                    ModelClass model = new ModelClass();
                    model = snapshot.getValue(ModelClass.class);
                }
            }

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

            }
        });

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