Skip to content

DataBinding

angcyo edited this page Jul 14, 2021 · 1 revision

使用入门

请依赖对应的-binding版本后缀名的版本, 否则将不支持DataBinding.

之后使用com.angcyo.dsladapter.DslViewHolder#binding获取binding对象,其他无变化.

demo代码:

class DslBindingTextItem : DslAdapterItem() {

    init {
        itemLayoutId = R.layout.item_bind_text_layout
    }

    override fun onSetItemData(data: Any?) {
        super.onSetItemData(data)
        updateAdapterItem()
    }

    override fun onItemBind(
        itemHolder: DslViewHolder,
        itemPosition: Int,
        adapterItem: DslAdapterItem,
        payloads: List<Any>
    ) {
        super.onItemBind(itemHolder, itemPosition, adapterItem, payloads)

        itemHolder.binding<ItemBindTextLayoutBinding>()?.data = itemData as? BindingData
    }
}