Skip to content

Instantly share code, notes, and snippets.

@le0nidas

le0nidas/debounce_handler.kt Secret

Created Mar 14, 2021
Embed
What would you like to do?
class MainActivity : AppCompatActivity() {
private var counter = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val bindings = ActivityMainBinding.inflate(layoutInflater)
setContentView(bindings.root)
with(bindings) {
userInput.doAfterTextChanged { text ->
userInput.handler.removeCallbacksAndMessages(counter)
userInput.handler.postDelayed(500L, ++counter) { userResult.text = text }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment