好吧,我有一个 ViewModel
带 setter/getter getTitle()
返回 MutableLiveData<String>
.
<EditText
style="@style/Widget.EditText.FullWidth"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/label_title"
android:inputType="text"
android:text="@={ viewModel.title }" />
一开始效果很好:EditText
包含 MutableLiveData
的值当它第一次出现时。但是,如果使用 MutableLiveData.setValue()
更新此数据的值(例如通过另一个 EditText
,或来 self 的代码),那么文本框内的值不会改变。我该如何解决这个问题?
最佳答案
这在 new version of Android Studio 中正常工作,它支持正确绑定(bind)到 LiveData
对象。
关于android - EditText LiveData 双向绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49723950/