Skip to content

A RecyclerView Adapter that can handle multiple item types without much boilerplate and can be reused on any screen with list content.

License

Notifications You must be signed in to change notification settings

kozmi55/Flexible-RecyclerView-with-Databinding

Repository files navigation

Flexible RecyclerView with Databinding

This is the sample app for the following article: https://proandroiddev.com/flexible-recyclerview-adapter-with-mvvm-and-data-binding-74f75caef66a

Handling event clicks (This is not covered in the article)

  • If you want to handle it in the ItemViewModel, just define a function there and for the root view of the ItemViewModel in the XML add the onClick with DataBinding. An example of this can be seen at the end of the story in the Making an ItemViewModel observable section.

  • If you want to handle the onClick in the CarListViewModel, you can do the same, just pass a lambda to the ItemViewModel in the constructor and you can call it from the XML.

  • If you want to handle it in the Fragment for example showing a dialog or navigating to an other screen you would need some kind of observable LiveData, where you push events, when an onClick happens. The fragment would observe that and execute the correct action. Example here.

Example of this can be found in this commit.

About

A RecyclerView Adapter that can handle multiple item types without much boilerplate and can be reused on any screen with list content.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages