Skip to content
Advertisement

I want to get all child of child items one by one in firebase database

here is model class :

I want that I get all food items from all categories one by one and than show every single food item data in recycler view

and after getting list of all items I want that I add only those items in a list which pin value is TRUE

JavaScript

here is the java class file code : when I check snapshot using snapshot.getValue() in log it gives me all categories also items, but it is not adding in a list…why ???

JavaScript

this is my database :

I want all food item from all category one by one

Advertisement

Answer

Your for (DataSnapshot dataSnapshot : snapshot.getChildren()){ loop only loops over one level in the database, so your dataSnapshot points to BBQ and then Chines, not to the individual food items.

Since you want to loop over two nested node levels, you need two nested loops in your code:

JavaScript
Advertisement