Skip to content

Instantly share code, notes, and snippets.

@alz-ahm
Last active March 15, 2019 12:54
Show Gist options
  • Save alz-ahm/9eb8b431a91bffa4d5cd6515846653a1 to your computer and use it in GitHub Desktop.
Save alz-ahm/9eb8b431a91bffa4d5cd6515846653a1 to your computer and use it in GitHub Desktop.
//Without extension
inputET.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) {
}
})
//With extension
inputET.afterTextChanged {
}
//Extension function
fun EditText.afterTextChanged(afterTextChanged: (String) -> Unit) {
this.addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
}
override fun afterTextChanged(editable: Editable?) {
afterTextChanged.invoke(editable.toString())
}
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment