[Android] Handling Text Changes in EditText in Data Binding

Writing time : 2021-11-06 02:02:20

Learn how to handle text changes of EditText in data binding in MVVM pattern.


Add app:addTextChangedListener property to EditText Element of XML.



Add methods set in XML to ViewModel object.

fun onEditTextWatcher(): TextWatcher {  
  return object : TextWatcher {  
      override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}  
      override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}  
      override fun afterTextChanged(s: Editable) {  
          // TODO