Fetch Data From Firebase Cloud Firestore to RecyclerView Using FirestoreRecyclerAdapter

Nur Rohman
AndroidPub
Published in
2 min readNov 1, 2017

A month ago Google launch Firebase Cloud Firestore, a fully-managed NoSQL document database for mobile and web app development. It’s designed to easily store and sync app data at global scale, and it’s now available in beta.

Firebase Cloud Firestore

Some awesome features of Firebase Cloud Firestore include:

  • Documents and collections with powerful querying
  • iOS, Android, and Web SDKs with offline data access
  • Real-time data synchronization
  • Automatic, multi-region data replication with strong consistency
  • Node, Python, Go, and Java server SDKs

For more details, you can read the docs here.

In this article i will give you a sample how to fetch data from Firebase Cloud Firestore in Android apps. In this case, we will use FirestoreRecyclerAdapter to populate data in RecyclerView.

FirestoreRecyclerAdapter is an adapter class from Firebase UI Database library. So, how do we get started?

Before you create the project in Android Studio, you should:

  1. Create a Firebase Project here.
  2. Go to Database menu and choose Cloud Firestore.
  3. Add Collection named "friends".
  4. In the "friends" collection, add some documents with some field (name, image, title, company) in the each documents. Also you should integrate the Firebase project with the project that will you create in Android Studio. For more information, go to the Firebase Docs.

Dependencies

Some dependencies thats should be implemented in your project:

Query

To retrive all documents in the collection use:

Using FirestoreRecyclerAdapter

Configure the adapter by building FirestoreRecyclerOptions:

Create FirestoreRecyclerAdapter:

I have create sample project for this article, you can clone the repo here:

Feel free to drop your comments below. Cheers~

--

--