Implementing Simple Data Binding

The next job is to hook up your RecyclerView. This is a job that you have done before. But this time, you will use data binding to speed up your work.

Data binding provides several benefits that make life easier when working with layouts. In simple cases, like the one you will see in this section, it allows you to access views without needing to call findViewById(…). Later, you will see more advanced uses of data binding, including how it helps you implement MVVM.

Start by enabling data binding and applying the kotlin-kapt plug-in in your app’s build.gradle file.

Listing 19.2  Enabling data binding (app/build.gradle)

apply plugin: 'kotlin-kapt'

android {
    ...
    buildTypes {
        ...
    }
    dataBinding { ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.