Android数据绑定不适用于Kotlin的class级授权
我的ViewModel:
class MyVM( app: Application, private val observableImpl: BaseObservable, /* other colaborators*/ ) : AndroidViewModel(app), Observable by observableImpl { var currencyCode: String by Delegates.observable("") { _, _, newValue -> /* business logic methods */ notifyPropertyChanged(BR.currencyCode) } @Bindable get }
我的布局:
当currencyCode
在数据模型中更新时, TextView
不会自动更改文本。
我试图摆脱从AndroidViewModel
inheritance和定义MyVM
,如下所示:
class MyVM(/* other colaborators*/) : BaseObservable() { }
它的工作。 问题是,我不能丢弃我的生产代码中的AndroidViewModel
的inheritance。
尽管有一个解决方法:
val currencyCode = ObservableField()
但我不熟悉在我的ViewModel中使用ObservableFields。 你有什么建议吗?
- 在使用Android Databinding和Kotlin的自定义BindingAdapter中使用lambda
- 如何在Kotlin中制作一个双向转换器? (在Java中工作)
- 数据绑定validation器错误,由Ilhasoft + Kotlin
- Kotlin和Android数据绑定(BuildTools 2.0.0)
- 詹金斯:Android项目未能建立(生成数据绑定/匕首类失败)
- 任务之间的Gradle依赖关系
- android数据绑定单元测试错误解析数据绑定编译器选项失败。 PARAMS:
- 无法生成视图绑定器java.lang.IndexOutOfBoundsException
- 使用DataBinding库设置背景颜色资源或null