Skip to content

Instantly share code, notes, and snippets.

@whalemare
Created November 3, 2018 05:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whalemare/394d1400c0298d56c097575c4b5fee1a to your computer and use it in GitHub Desktop.
Save whalemare/394d1400c0298d56c097575c4b5fee1a to your computer and use it in GitHub Desktop.
fun TextView.onTextChanged(handler: (text: CharSequence) -> Unit): TextWatcher {
val watcher = object : TextWatcher {
override fun afterTextChanged(editable: Editable?) {
}
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(text: CharSequence?, p1: Int, p2: Int, p3: Int) {
(text ?: "").let(handler::invoke)
}
}
addTextChangedListener(watcher)
return watcher
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment