EditText LiveData Two-way binding

女生的网名这么多〃 提交于 2019-12-23 09:26:59

问题


Okay, so I have a ViewModel with a getter getTitle() that returns 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 }" />

This works fine at first: the EditText contains the value of the MutableLiveData when it first appears. However, if the value of this data is updated using MutableLiveData.setValue() (such as by another EditText, or from my code), then the value inside of the text box does not change. How do I fix this?


回答1:


This works properly in the new version of Android Studio, which supports binding to LiveData objects properly.



来源:https://stackoverflow.com/questions/49723950/edittext-livedata-two-way-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!