Showing Timer in android

让人想犯罪 __ 提交于 2019-12-11 02:24:46

问题


My objective is to display a simple timer clock on my screen where it starts from 20 and goes on decreasing and when it becomes 0 I want to start an action. How to achieve this ? Thanks in advance


回答1:


I don't know how you want to display it but you can do this also just by taking a TextView and keep changing its Text every second.

static int i = 20;
 new CountdownTimer(20000, 1000) {

     public void onTick(long millisUntilFinished) {
         i = i-1;
         mTextField.setText(String.valuOf(i));
     }

     public void onFinish() {
         //do your stuff here
     }
  }.start();


来源:https://stackoverflow.com/questions/7592863/showing-timer-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!