Android Lists Made Easy: DataBinding + RecyclerViewBindingAdapter Library

RecyclerViewBindingAdapter Library

This library provides a powerful yet reusable RecyclerView adapter that leverages ObservableArrayList and DataBinding to simplify your life. Tell the adapter which layouts your models map to and then just modify your observable list and the adapter takes care of the rest. Its that simple! Check out the library and example app source code here.


Step 1:


Add jitpack repository to you project's build.gradle file


Step 2:

Enable Android data binding and add library dependency in the module's build.gradle file that you will be using the library in. You will need data binding to create layouts bound to ViewModels. The adapter dynamically creates all the rows and manages recycling of the layouts.


Step 3:


Create ObservableArrayList that will hold all the view models and initialize EasyRecyclerAdapter with it. Set up the mappings between the layouts you intend to show in the list and the view model and the variable id (variable name) from the layout's <variable> tag.

Step 4:

For each row you need to create a view model that has some data and a layout with elements that use ViewModel's properties.


and the layout uses the view model.
Resources:
-Source code for library and sample app here
-My intro lesson on DataBinding here
-Official DataBinding documentation here

Liked this blog post? Want to learn more? 

Take my Udemy course on Android Data Binding here:

course image 


Comments

Popular posts from this blog

Android Data Binding : Dynamic RecyclerView Adapter

Android Architecture Components : LiveData

Android Data Binding : Tricks and Magic