I am trying to retrieve a nested list of workouts from a Realtime Database and I don’t know how to do it.
I made some research and still couldn’t really figure out how am supposed to do it.
The Realtime Database JSON file looks like this :
I am looking to retrieve data by workout, for example, if someone presses the workout one button I should retrieve the full workout one object. but I don’t know how am supposed to design my query request nor how am supposed to structure my model object that conceives the received data.
2
Answers
I think below line code help you.
Reference link :- https://firebase.google.com/docs/database/android/lists-of-data
As I see in your screenshot, under the "Workout one" node, you have two nested levels of data. So to get all exercises for each day, you have to loop over the children twice:
Please also don’t forget that the Firebase API is asynchronous. So any code that needs data from the database needs to be inside the
onComplete()
method, or be called from there. To understand better, I recommend you check the following resource: