我有:
function ofTable(...)
return {...}
end
具有activity.java:
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<data>
<import type="android.view.View" />
<variable name="vm" type="com.my.package.viewmodel.SplashActivityVM" />
</data>
<android.support.v7.widget.LinearLayoutCompat
bla...>
<TextView
bla...
android:text='@{vm.status}'
bla... />
bla...
和我的ViewModel:
@Override
protected void onCreate(Bundle savedInstanceState) { bla... }
private void observeStatus(SplashActivityVM viewModel) {
viewModel.getStatus().observe(this, status -> {
if (status != null) {
mBinding.setVm(viewModel);
} else { }
mBinding.executePendingBindings();
});
}
我收到以下错误消息:
msg:找不到具有参数类型的属性“ android:text”的设置器 android.arch.lifecycle.MutableLiveData 在android.widget.TextView上。
怎么了?
答案 0 :(得分:0)
您需要为自己的SplashState自定义binding adapter
TextViewAdapters.kt
@BindingAdapter("android:text")
fun setText(view: TextView, state: SplashState) {
view.text = state.toString()
}
@Override
protected void onCreate(Bundle savedInstanceState) { bla...
mBinding.setLifecycleOwner(this);
}
@Override
protected void onCreate(Bundle savedInstanceState) { bla...
mBinding.setLifecycleOwner(this);
mBinding.setvm(viewModel);
}