Last active
March 21, 2022 07:53
-
-
Save le0nidas/aa863df64c647cdec956c5657b5bac1e 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
fun EditText.debounce(delay: Long, action: (Editable?) -> Unit) { | |
doAfterTextChanged { text -> | |
var counter = getTag(id) as? Int ?: 0 | |
handler.removeCallbacksAndMessages(counter) | |
handler.postDelayed(delay, ++counter) { action(text) } | |
setTag(id, counter) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment