Skip to content

Instantly share code, notes, and snippets.

@le0nidas
Created March 14, 2021 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save le0nidas/9e0817baaed43f83bf23a9261b302eeb to your computer and use it in GitHub Desktop.
Save le0nidas/9e0817baaed43f83bf23a9261b302eeb to your computer and use it in GitHub Desktop.
class MainActivity : AppCompatActivity() {
private var timer = Timer()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val bindings = ActivityMainBinding.inflate(layoutInflater)
setContentView(bindings.root)
with(bindings) {
userInput.doAfterTextChanged { text ->
timer.cancel() // cancel any previous delay
timer = Timer() // schedule a new one
timer.schedule(500L) {
// we are in a background thread here
userInput.handler.post { userResult.text = text }
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment