Skip to content

Instantly share code, notes, and snippets.

@ananth10
Created August 30, 2020 06:04
Show Gist options
  • Save ananth10/b78d7753ff2ef59edb481ff90d1af2f3 to your computer and use it in GitHub Desktop.
Save ananth10/b78d7753ff2ef59edb481ff90d1af2f3 to your computer and use it in GitHub Desktop.
This is common TextWatcher for EditText component to avoid boiler plate code!!
class CommonTextWatcher(
private val beforeChanged:((CharSequence?,Int,Int,Int)->Unit)={_,_,_,_->},
private val afterChanged:((Editable?)->Unit)={},
private val onChanged:(CharSequence?,Int,Int,Int)->Unit
):TextWatcher {
override fun afterTextChanged(p0: Editable?) {
afterChanged(p0)
}
override fun beforeTextChanged(char: CharSequence?, start: Int, count: Int, after: Int) {
beforeChanged(char,start,count,after)
}
override fun onTextChanged(char: CharSequence?, start: Int, before: Int, count: Int) {
onChanged(char,start,before,count)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment