<!-- list_item_sleep_night.xml -->
<layout
...>
<data>
<variable
name="sleep"
type="com.example.android.trackmysleepquality.database.SleepNight" />
</data>
...
</layout>
In a previous codelab, you used the Transformations class to take LiveData and generate formatted strings to display in text views. However, if you need to bind different types, or complex types, you can provide binding adapters to help data binding use those types. Binding adapters are adapters that take your data and adapt it into something that data binding can use to bind a view, like text or an image.
You are going to implement three binding adapters, one for the quality image, and one for each text field. In summary, to declare a binding adapter, you define a method that takes an item and a view, and annotate it with @BindingAdapter. In the body of the method, you implement the transformation. In Kotlin, you can write a binding adapter as an extension function on the view class that receives the data.
BindingUtils.kt & list_item_sleep_night.xml