Created
September 5, 2017 02:11
-
-
Save maxost/61887e875bd9d2869056efa8f35a6a52 to your computer and use it in GitHub Desktop.
Kotlin: simple onTextChanged listener in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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