I know how to create a simple countdown timer in Java. But I'd like to create this one in Kotlin.
package android.os; new CountDownTimer(20000, 1000) { public void onTick(long millisUntilFinished) { mTextField.setText("seconds remaining: " + millisUntilFinished / 1000); } public void onFinish() { mTextField.setText("Time's finished!"); } }.start();
How can I do it using Kotlin?
You can use Kotlin objects:
val timer = object: CountDownTimer(20000, 1000) { override fun onTick(millisUntilFinished: Long) {...} override fun onFinish() {...} } timer.start()
1.4m articles
1.4m replys
5 comments
56.9k users