Skip to content

Instantly share code, notes, and snippets.

@ricardoalcocer
Created May 13, 2020 04:34
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 ricardoalcocer/17ec528d5eb4095243fd0b8ae5add461 to your computer and use it in GitHub Desktop.
Save ricardoalcocer/17ec528d5eb4095243fd0b8ae5add461 to your computer and use it in GitHub Desktop.
Kotlin Android Countdown
private fun stopCountDown(){
val t = Toast.makeText(this,"Stopping countdown",Toast.LENGTH_SHORT).show()
timer1.cancel()
timer1IsRunning=false
}
private fun startCountDown(){
timer1 = object : CountDownTimer(duration, interval) {
override fun onFinish() {
txtTimer1.text = "0"
timer1IsRunning=false
}
override fun onTick(millisUntilFinished: Long) {
txtTimer1.text = (millisUntilFinished / 1000).toString()
}
}
timer1.start()
timer1IsRunning=true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment