Skip to content
Advertisement

Retrieve subcollection data from Firestore in Android

I keep failed to retrieve the data from subcollection “Diary” when trying on click on a RecyclerView. What I want is when I on click on a RecyclerView, it will display that data stored in the “Diary”. What’s the problem with my codes?

RecyclerView Java codes:

JavaScript

Stored data Java codes:

JavaScript

Retrieve data Java codes:

JavaScript

Database structure:

enter image description here

enter image description here

Output:

enter image description here

enter image description here

Advertisement

Answer

I believe the problem in your code is in this line:

JavaScript

Where you are using .document().getId(); but without specifying which document you want, which makes id not have the expected value and because of that you don’t get any results in the comparison that uses that value later in your execution. To fix that you would need to have this Id stored somewhere and pass it as a parameter to your getDiary() function, or something similar to that.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement