简体   繁体   中英

How to retrieve data child of child from firebase / Android

Here is my firebase database

Here is the info.class

Here is the insert

I want to get all the data from firebase to List View

How can i get all data under "information" data list ? please help

db = FirebaseDatabase.getInstance();
ref = db.getReference("infomation");

  protected void onStart() {
    super.onStart();

    ref.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            infoList.clear();
            for (DataSnapshot infoSnapshot : dataSnapshot.getChildren()){

                 info info = infoSnapshot.getValue(info.class);
                 infoList.add(info);

            }
            InfoList adapter = new InfoList(Welcome.this, infoList);
            listViewInfo.setAdapter(adapter);

        }

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

        }
    });
}

In your insertion part, you need to change it like below,

DatabaseReference ref = FirebaseDatabase.getInstance().getReference("information");
ref.child( FirebaseAuth.getInstance().getCurrentUser().getUid()).setValue(in);

but if you want to save data like save the data like

information >uid> random value > then the data

that use change data retrieving part like below

 for (DataSnapshot infoSnapshot : dataSnapshot.getChildren().getChildren()){

                 info info = infoSnapshot.getValue(info.class);
                 infoList.add(info);

}

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