この問題に対して私が思いつくことができる最善の解決策は、新しいBindableメソッドを導入することでした。
前:
item_recyclerview.xml
:
<EditText
...
android:enabled="@{myViewModel.myDataModelClass.lastAddedItem && !myViewModel.myDataModelClass.editTextDisabled}"
/>
MyDataModelClass
:(これは私のビューモデルで開催されています)
...
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
:(これは私のビューモデルで開催されています)
...
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();
}