Skip to content

Instantly share code, notes, and snippets.

@theerasan
Last active July 12, 2017 06:59
Show Gist options
  • Save theerasan/44719dcdff357551441eed3dad8fb81d to your computer and use it in GitHub Desktop.
Save theerasan/44719dcdff357551441eed3dad8fb81d to your computer and use it in GitHub Desktop.
class TextWatcherAdapter(private var field: (String) -> Unit) : TextWatcher {
private var isInEditMode = false
var tmp = ""
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
}
override fun afterTextChanged(s: Editable) {
setText(s.toString())
}
fun setText(s: String) {
if (tmp != s) {
isInEditMode = true
field.invoke(s)
tmp = s
isInEditMode = false
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment