Enabling data binding
By default in an Android project, the data binding capabilities are turned off. You'll need to enable them in your project's build.gradle
file by hand. Follow these quick steps to enable the data binding system:
- Start by locating the
build.gradle
file for your application module in the Android panel in Android Studio:
- Open this file and locate the
android
block:
android { compileSdkVersion 26 // ... }
- At the end of the
android
block, add the following snippet to enable data binding:
android { compileSdkVersion 26 // ... dataBinding { enabled = true } }
- Once you save this file, Android Studio will open a banner at the top of the file, telling you that it needs to sync the project. Click on the
Sync Now
link on the right-hand side of the banner and wait for the sync to complete.
Congratulations! You've just enabled the data binding framework on your project. Now you can get started, making use of the data binding system in your layout files, which will simplify...