Last active
March 15, 2019 12:54
-
-
Save alz-ahm/9eb8b431a91bffa4d5cd6515846653a1 to your computer and use it in GitHub Desktop.
This file contains 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
//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