Countdown Timer required on Android

前端 未结 4 1739
粉色の甜心
粉色の甜心 2020-12-06 23:05

Here is the link where i have discussed about a countdown timer of format(mm:ss) in Java:

Java console code for StopWatch/Timer?

Now i want to display (and u

4条回答
  •  暖寄归人
    2020-12-06 23:20

    try this code.....

    tv = new TextView(this);
        this.setContentView(tv);
    
    //10000 is the starting number (in milliseconds)
    //1000 is the number to count down each time (in milliseconds)
    MyCount counter = new MyCount(10000,1000);
    
    counter.start();
    
    }
    
    //countdowntimer is an abstract class, so extend it and fill in methods
    public class MyCount extends CountDownTimer
    {
    
    public MyCount(long millisInFuture, long countDownInterval) 
    {
    super(millisInFuture, countDownInterval);
    }
    
    public void onFinish()
    {
    tv.setText("Time Up!");
    }
    
    public void onTick(long millisUntilFinished) 
    {
    tv.setText("Time Left : " + millisUntilFinished/1000);
    
    }
    

提交回复
热议问题