如何在RxJava中使用DataBindings?

时间:2019-06-27 18:10:47

标签: android rx-java android-databinding

我正在尝试将dataBindingRxJava结合使用,以使它看起来像这样:

layout.xml:

<android.support.constraint.ConstraintLayout
        //...
        app:rxClick="@{viewModel.onTap}">
    <TextView
            //...
            android:text="@{viewModel.title}"
    </TextView>
    //...

ViewModel:

class ViewModel {
    val title = PublishSubject.create<String>()
    val onTap = PublishSubject.create<Void>()
    //...
}

但是我找不到找到这种方法的简单方法。

我在研究时发现的一件事是ObservableField库中包含的LiveDatadataBinding。而且我认为这不是一个好的解决方案,因为rxJava更复杂,并且ObservableField似乎与rxJava不兼容。

我发现的另一件事是这个库https://github.com/ArthurVimond/RxBindingAdapters,它很适合这种情况。但这不起作用,编译时会出现错误:

e: [kapt] An exception occurred: android.databinding.tool.util.LoggedErrorException: Found data binding errors.
****/ data binding error ****msg:cannot find type element for io.reactivex.subjects.Subject

我还有其他选择吗?有什么建议吗?

0 个答案:

没有答案