Creating a ViewHolder with data binding

As you can see from building a traditional ViewHolder implementation, there is quite a lot of work and boilerplate code required just to put the data from a single item onto the screen in a layout. Further, it's actually quite expensive in its own right, because every one of the ViewHolder instances creates and holds an instance of the DateFormatter where they can easily be shared between all the ClaimItemViewHolder instances for a RecyclerView.

In cases like this, data binding can make a huge difference. Using a few tricks, you can actually create a completely generic ViewHolder implementation that will work for any data object in your application (assuming that you can bind it to a layout file). First, ...

Get Hands-On Android UI Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.