ANDROID RECYCLERVIEW - DiffUtil and Data binding with RecyclerView 02
Use DataBinding with RecyclerView
<!-- list_item_sleep_night.xml -->
<layout
...>
<data>
<variable
name="sleep"
type="com.example.android.trackmysleepquality.database.SleepNight" />
</data>
...
</layout>
Create binding adapters
Concept
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.
Before
After
BindingUtils.kt & list_item_sleep_night.xml
Author And Source
이 문제에 관하여(ANDROID RECYCLERVIEW - DiffUtil and Data binding with RecyclerView 02), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@dmitry-_-11/ANDROID-RECYCLERVIEW-DiffUtil-and-Data-binding-with-RecyclerView-02저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)