In Yigit Boyar and George Mount\'s talk on Android Databinding they illustrate how easy it is to bind to TextWatcher\'s onTextChanged (at 13:41). O
create a class (I named him BindingAdapters). Then define your bindingAdapter methods.
@BindingAdapter("app:textChangedListener")
fun onTextChanged(et: EditText, number: Int) {
et.addTextChangedListener(object : TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
if (et.text.toString().trim().length >= number) {
et.setBackgroundColor(Color.GREEN)
}
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) {}
})
}
set this attr for editText in xml layout