Skip to content
Advertisement

How do I display child of child’s data from firebase in my RecyclerView?

I want to show data of all children inside all the Categories from the database (added the image below of what my database looks). I am adding data to my RecyclerView using the adapter which needs FirebaseRecyclerOptions object to be passed. I saw one answer where DataSnapshot was used to get child of child data, I tried to get the data using that and it showed me when I logged it in logcat (the commented code is what I tried using), but I do not know how to use that with my Adapter class.

This is what my database looks, I want the data inside of the highlighted fields:

JavaScript

In the below code, SCard is my Model Class and SCardAdapter is my Adapter Class.

This is my Fragment (HomeFragment) where I’m adding data into recyclerview:

JavaScript

This is my Adapter Class:

JavaScript

Advertisement

Answer

First of all, you need to create 2 loops since your json looks like that and store them inside an arrayList. You are suppose to get all the data there inside the arrayList.

JavaScript

Next you need to create your own adapter. You can search on Google also for more information. But you will get the point here.

JavaScript
Advertisement