Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Last active March 21, 2022 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save le0nidas/aa863df64c647cdec956c5657b5bac1e to your computer and use it in GitHub Desktop.
Save le0nidas/aa863df64c647cdec956c5657b5bac1e to your computer and use it in GitHub Desktop.
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