

RecyclerView With Android DataBinding
source link: https://www.ravirupareliya.com/blog/recyclerview-with-android-databinding/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Home Android / DataBinding RecyclerView With Android DataBinding
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 :

Ravi Rupareliya
Ravi Rupareliya September 11, 2016
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK