How can I pause the timer in android?

后端 未结 2 625
天涯浪人
天涯浪人 2021-01-07 05:04

I have gone through the link http://dewful.com/?tag=basic-android-timer regarding the timer application in android. It is working fine. I need to add the pause butto

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-07 05:42

    public class TimerActivity extends Activity
    {
        EditText e1;
        MyCount counter;
        Long s1;
        /** Called when the activity is first created. */ 
        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            e1=(EditText)findViewById(R.id.editText1);
            counter= new MyCount(5000,1000);
            counter.start();
        }
        public void asdf(View v)
        {
            switch(v.getId())
            {
                case R.id.button1:         counter.cancel();
                break;
                case R.id.button2:         counter= new MyCount(s1,1000);
                counter.start();
            }
        }
        public class MyCount extends CountDownTimer
        {
            public MyCount(long millisInFuture, long countDownInterval)
            {
                super(millisInFuture, countDownInterval);
            }
            @Override     public void onFinish()
            {
                e1.setText("DONE");
            }
            @Override     public void onTick(long millisUntilFinished)
            {
                s1=millisUntilFinished;
                e1.setText("left:"+millisUntilFinished/1000);
            }
        }
    }
    

提交回复
热议问题