Skip to content

Instantly share code, notes, and snippets.

@adrianhall
Created April 10, 2018 15:21
Show Gist options
  • Save adrianhall/ed038d1561739a0eefd886180e9d53bb to your computer and use it in GitHub Desktop.
Save adrianhall/ed038d1561739a0eefd886180e9d53bb to your computer and use it in GitHub Desktop.
An extension function for implementing a text change watcher on EditText
fun EditText.afterTextChanged(afterTextChanged: (String) -> Unit) {
this.addTextChangedListener(object: TextWatcher {
override fun afterTextChanged(s: Editable?) {
afterTextChanged.invoke(s.toString())
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { }
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { }
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment