0

This is is firebase database structure

I want to access the highlighted values of child from all the children of "services" in the attached image and store them in an array. Help me to achieve this.

Community
  • 1
  • 1
laxminarayan1998
  • 838
  • 8
  • 13

1 Answers1

0
public static void getData(){
    DatabaseReference database = FirebaseDatabase.getInstance().getReference("Services");
    database_course.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {

            for (DataSnapshot ds : dataSnapshot.getChildren()) {
                String key = ds.getKey(); //"AC Repair","Fridge Repair"
                HashMap<String, HashMap<String,HashMap<String,Object>>> servicesHashMap = ds.get(key);
                //Icon Source
                String imageUrl = (String) servicesHashMap.get(key).get("Icon Source").get("imageUrl");
                String name = (String) servicesHashMap.get(key).get("Icon Source").get("name");
                //Rate Card
                HashMap<String,Object> serviceType = (HashMap<String, Object>) servicesHashMap.get(key).get("Rate Card").get("serviceType1");
                int  price = (int) serviceType.get("price");//if price is 1300
                //int  price = (int) serviceType.get("price");//if price is "1300"
                String type = (String)serviceType.get("type");
                //Service Image
                HashMap<String, Object> url = servicesHashMap.get("Service Image").get("url");

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

        }
    });
}
Ruyut
  • 151
  • 11