Data Binding
Data binding links the views in your layout to data from a source such as a ViewModel. Instead of adding code to find the views in the layout file and updating them when the value from the ViewModel changes, data binding can handle that for you automatically.
To use data binding in your Android project, you should add the following in the android
block of the app/build.gradle
file:
buildFeatures { dataBinding true }
In the layout file, you must wrap the root element with a layout tag. Inside the layout tag, you need to define the data
element for the data to be bound to this layout file:
<layout xmlns:android="http://schemas.android.com/apk/res/android"> <data> <variable name="movie" type="com.example.model.Movie"/> </data> <ConstraintLayout ... /> </layout...