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
Nice blog, it is very impressive.
ReplyDeleteKotlin Android Training in Chennai
Kotlin Online Training
Kotlin Course in Bangalore