对于这个问题,我能想到的最佳解决方案是引入新的Bindable方法。
之前:
item_recyclerview.xml
:
<EditText
...
android:enabled="@{myViewModel.myDataModelClass.lastAddedItem && !myViewModel.myDataModelClass.editTextDisabled}"
/>
MyDataModelClass
:(正在我的viewmodel中保存)
...
private boolean lastAddedItem;
private boolean editTextDisabled;
...
@Bindable
public boolean isLastAddedItem() {
return lastAddedItem;
}
public void setLastAddedItem(boolean lastAddedItem) {
this.lastAddeditem = lastAddedItem;
notifyPropertyChanged(BR.lastAddedItem);
}
@Bindable
public boolean isEditTextDisabled() {
return editTextDisabled;
}
public void setEditTextDisabled(boolean editTextDisabled) {
this.editTextDisabled = editTextDisabled;
notifyPropertyChanged(BR.editTextDisabled);
}
后:
item_recyclerview.xml
:
<EditText
...
android:enabled="@{myViewModel.myDataModelClass.enableEditing}"
/>
MyDataModelClass
:(正在我的viewmodel中保存)
...
private boolean lastAddedItem;
private boolean editTextDisabled;
...
@Bindable
public boolean isLastAddedItem() {
return lastAddedItem;
}
public void setLastAddedItem(boolean lastAddedItem) {
this.lastAddeditem = lastAddedItem;
notifyPropertyChanged(BR.lastAddedItem);
notifyPropertyChanged(BR.isEnableEditing);
}
@Bindable
public boolean isEditTextDisabled() {
return editTextDisabled;
}
public void setEditTextDisabled(boolean editTextDisabled) {
this.editTextDisabled = editTextDisabled;
notifyPropertyChanged(BR.editTextDisabled);
notifyPropertyChanged(BR.isEnableEditing);
}
@Bindable
public boolean isEnableEditing() {
return isLastAddedItem() && !isEditTextDisabled();
}