我有:
<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...
使用activity.java:
@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();
});
}
和我的视图模型:
public class SplashActivityVM extends AndroidViewModel implements ViewModel {
private final MutableLiveData<SplashState> mObservableStatus = new MutableLiveData<>();
public MutableLiveData<SplashState> getStatus() { return mObservableStatus; }
public SplashActivityVM(@NonNull Application application) { super(application); }
// bla...
我收到以下错误:
msg:在 android.widget.TextView 上找不到参数类型为 android.arch.lifecycle.MutableLiveData 的属性“android:text”的设置器。
怎么了?