0

What is the best way to display data in a RecylerView in Android from FireStore?

My Firestore database has two collections as following.

Posts
 ---  Title
 ---  Image
 ---  User_ID

Users
 ---  User_ID
 ---  User_Name

I want to display Posts in a RecylerView with Title(Posts),Image(Posts) and User_Name(Users).

So what is the best way to fetch data from Firestore? What is the recommend way to write an adapter for this scenario?

AD Mark
  • 115
  • 1
  • 7

3 Answers3

0

You can use retrofit to fetch the data and put it into pojo class objects. And pass it into recyclerView's adapter.

Suhas
  • 159
  • 1
  • 11
  • I can fetch the post data and display in a RecylerVIew. But my problem is we can not join collection in Firestore. I want to display user_name in a post. To do this again I want fetch user details from User collection. What I want to know is that the best way to do this? Thanks – AD Mark Sep 17 '18 at 06:25
0

As said in a youtube video from Google, you need to add some user details in Posts collection like his name and icon url. Link to the specified video : https://youtu.be/v_hR4K4auoQ?t=6m40s

tmagnier
  • 41
  • 6
0

The best way is to use FirestoreRecyclerAdapter

FirestoreRecyclerAdapter — binds a Query to a RecyclerView and responds to all real-time events included items being added, removed, moved, or changed. Best used with small result sets since all results are loaded at once.

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134