Skip to content

Instantly share code, notes, and snippets.

@maxost
Created September 5, 2017 02:11
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 maxost/61887e875bd9d2869056efa8f35a6a52 to your computer and use it in GitHub Desktop.
Save maxost/61887e875bd9d2869056efa8f35a6a52 to your computer and use it in GitHub Desktop.
Kotlin: simple onTextChanged listener in Android
fun TextView.onTextChanged(block: (String) -> Unit) {
addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
block(s.toString())
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment