I have an EditText and i want to do some action every time the user inserts a value.
In the old times, before databinding with LD, I would just have a method in my Activity which performs the action, and reference it in the layout like this:
In Layout:
<EditText
android:onTextChanged="textChanged()"
Now i´m using databinding with LiveData. I have a field in my VM referenced from the UI, and using two-way databinding, so the field is updated automatically. But what if i want to do something more than just updating the value of the field? Can i define a method to run other actions, like for example save the value in the database?
In Layout:
<EditText
android:text="@={viewmodel.myField}"
In ViewModel:
val myField = MutableLiveData<String>()
*Note: I want it to be done in the VM. I know i could create an observer in the Activity observing the field in the VM, but that is just if i want some UI change done. I want to do some business logic when the value changes, not UI.