data class User(
private val _id: Long,
private var _name: String,
) : BaseObservable() {
val id: Long
get() = _id
var name: String
@Bindable get() = _name
set(value) {
_name = value
notifyPropertyChanged(BR.name)
}
@Bindable
var age: Int = false
set(value) {
field = value
notifyPropertyChanged(BR.age)
}
}
2条答案
按热度按时间dgiusagp1#
您可以用途:
kzmpq1sx2#
而不是在Kotlin中进行数据绑定,你必须使用viewBinding,因为它更容易使用,并且在android中得到官方支持
https://developer.android.com/topic/libraries/view-binding