RecyclerView With Android DataBinding

In I/O 2015 Google announced a data binding library for Android. With Data Binding, you create an ongoing link between an element in the user interface and a value. Data Binding is the process that establishes a connection between the application UI and business logic.

In this post we will learn how to integrate recyclerview with android Data Binding.

Step 1 : Enable dataBinding in your module level gradle, here is how your build.gradle should look like.

Step 2 : Create POJO/Model class called User with 3 parameters name, profile_image & age.

Step 3 : Create a layout for Recycler list items

Here user will be model class reference variable, you can have any number of variables as you need. <layout> will contain your model class information using which you will notify your controls about value they are going to show.

Step 4 : Create an adapter for Recyclerview called UserAdapter

Here
binding = DataBindingUtil.bind(itemView); will create binding for your recycler_item layout and return view.
binding.setUser(user); will set User data to recycler items.

Step 5 : Write xml code for your activity/fragment layout

Step 6 : Write your code in activity/fragment to attach adapter to Recyclerview.

Output :

RecyclerView Android DataBinding

Follow me

Ravi Rupareliya

He is author of Android Gig. He loves to explore new technologies and have worked on Android, React Native, Action on Google and Flutter.
Ravi Rupareliya
Follow me

Latest posts by Ravi Rupareliya (see all)

Advance DataBinding in Android
Being More Productive With Android Studio – Part 1