【发布时间】:2020-11-20 08:08:02
【问题描述】:
您好,我从 MVVM 和 DataBinding 开始,所以我要做的是创建一个简单的 viewModel,其中包含一个字段让我们说名称,当用户单击按钮时,它会检查 editText 是否为空,如果是,请转到下一个活动(发送名称)。
我试过的是:
这是我的视图模型
class MainActivityViewModel : ViewModel() {
private val _userName = MutableLiveData<String>()
val username : LiveData<String> = _userName
//Here I'd like to know if I have to use MutableLiveData<NameStatus> and this name status is Filled / Empty so my activity can react to it and show an error or something
//And then when tapping the button it should check the edittext value and send it to next activity.
}
我还考虑在布局中添加类似按钮被禁用的内容,如果 editText 大小为 0,这可能是一个选项,但我想知道第一个选项,以便我可以处理状态并对说明 EditText 是填充还是空。
【问题讨论】:
-
您遇到的困难究竟是什么?什么是 NameStatus?
标签: android kotlin mvvm data-binding