How to use FirebaseRecyclerAdpater with latest Firebase Dependencies in Android

Ankit Suda
Android Grid
Published in
2 min readJan 22, 2018

Hey There Awesome Geeks! Ankit is here with another tutorial on Firebase. In this tutorial you’ll learn how to implement latest FirebaseRecyclerAdpater in Android, I am saying ‘latest’ because newer dependencies lost the support for populateView(). So without wasting anymore time let’s get started.

Source Code

Output

Reference

Take a look at the official documentation for more details.

Let’s Code

Step 1) Create a new Android Studio project and connect it to Firebase and Realtime Database support.

Step 2) After creating the project and connecting it to Firebase add below dependencies to app level build.gradle.

Step 3) Now go to here and copy dependency that is saying Firebase Realtime Database to your app level build.gradle.

NOTE: Make sure Firebase and FirebaseUi dependencies version are same, or you’ll get some errors when you run the app. At this time (When I was writing this post) use below dependencies.

Step 4) Create a Model class and copy below code in it or use your own.

Step 5) Create a list_item.xml layout. We’ll use it as a list item.

Step 6) Open activity_main.xml and modify it with below code.

Step 7) Now we’re going to write some important code. Open MainActivity.java and add these vars.

Step 8) Now declare the views in onCreate()method

Step 9) To show data in list we need some data to be there in database, so we’re going to add data via this method

The “posts’ is the node where we’ll save our data.

Step 10) Setup the RecyclerView

Step 11) Now we need a ViewHolder to handle out views in each position.

Note: Add below code in MainActivity.java as a child class.

Step 12) Now we’re going to fetch the data from Database

Step 13) If you run the app, it will not show any data because we have to add the below listeners

Step 14) That’s all folks. Now run your app and check whether it’s working or not.

--

--

Ankit Suda
Android Grid

Ankit is self-taught Android App Programmer. He provides Android App Development Tutorials to Android Grid.