CountDownTimer countdown is very simple and practical,

Source: Internet
Author: User

CountDownTimer countdown is very simple and practical,

This is very simple, so the Code has nothing to explain. It is to remember this API.

Public class MainActivity extends AppCompatActivity {

Private TextView textView; private CountDownTimer downTimer; private long time = 100*1000; // The total countdown time ms @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); setContentView (R. layout. activity_main); textView = (TextView) findViewById (R. id. tv1); initViews ();} private void initViews () {// 1000 indicates that onTick () downTimer = new CountDownTimer (time, 1000) is executed every 1000 ms) {@ Override public void onTick (long millisUntilFinished) {time-= 1000; textView. setText (time/1000 + "") ;}@ Override public void onFinish () {Toast. makeText (MainActivity. this, "ended", Toast. LENGTH_SHORT ). show () ;};} public void doClick (View view) {switch (view. getId () {case R. id. start: downTimer. start (); // start countdown break; case R. id. stop: downTimer. cancel (); // pause break ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.