I am trying to update an EditText from View page in Kotlin using mvvm. But when ViewModel is initialised the default value is binding but when i change the value from EditText onClick listener its not updating the UI.
xml
<EditText
android:id="@+id/itemsDatePicker"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_gravity="end"
android:text="@={itemviewmodel.selectedDateText}"
android:onClick="@{itemviewmodel.datePickerOnClick}"
android:hint="Select Date"
tools:ignore="AutoFill,TextFields" />
View Model
fun datePickerOnClick(view: View) {
showDatePicker.value=true
}
View
vm.showDatePicker.observe(this,androidx.lifecycle.Observer{ s->
val myCalendar: Calendar = Calendar.getInstance()
val date =
DatePickerDialog.OnDateSetListener { view, year, monthOfYear, dayOfMonth -> // TODO Auto-generated method stub
myCalendar.set(Calendar.YEAR, year)
myCalendar.set(Calendar.MONTH, monthOfYear)
myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth)
//This place should update the ui with selected date but not working as expected
vm.selectedDateText.value =DateHelper.getTodayDate(myCalendar.getTime())
}
DatePickerDialog(
this, date, myCalendar
.get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
myCalendar.get(Calendar.DAY_OF_MONTH)
).show()
})
Any help to overcome this problem is much appreciated. Thanks in advance. :)