Last active
July 12, 2017 06:59
-
-
Save theerasan/44719dcdff357551441eed3dad8fb81d to your computer and use it in GitHub Desktop.
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
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