Solusi terbaik yang dapat saya temukan untuk masalah ini adalah memperkenalkan metode Bindable baru.
Sebelum:
item_recyclerview.xml
:
<EditText
...
android:enabled="@{myViewModel.myDataModelClass.lastAddedItem && !myViewModel.myDataModelClass.editTextDisabled}"
/>
MyDataModelClass
: (yang diadakan di viewmodel saya)
...
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);
}
Setelah:
item_recyclerview.xml
:
<EditText
...
android:enabled="@{myViewModel.myDataModelClass.enableEditing}"
/>
MyDataModelClass
: (yang diadakan di viewmodel saya)
...
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();
}