Android uses Hangler countdown

Source: Internet
Author: User


Above an edit box enter the number to Countdown
Gets displayed later on the TextView above
Click Start, the number on the TextView is reduced

PrivateTextView Tvtime;PrivateEditText Inputtv;PrivateButton btnhq,btnbg,btnzt;//The number used to hold the countdown    Private intIPrivateTimer timer;PrivateTimerTask task; Public void OnClick(View v) {Switch(V.getid ()) { CaseR.id.button1:string time = Inputtv.gettext (). toString (); Tvtime.settext (time); i = Integer.parseint (time); Break; CaseR.id.button2:start (); Break; CaseR.id.button3:timer.cancel (); Break;}}
handler Mhandler = new  Handler () {public  void                  Handlemessage  (android.os.Message msg) {tvtime.settext (Msg.arg1+);            //equals zero when not self-decrement  if  (Msg.arg1==0 )            {Timer.cancel ();            }else  {start ();    }            }; };
privatevoidstart() {        new Timer();        new TimerTask() {            @Override            publicvoidrun() {                i--;                Message msg = mHandler.obtainMessage();                //将i放入msg里面                msg.arg1 = i;                mHandler.sendMessage(msg);            }        };        //一定要记得部署这个方法        1000);    }

Android uses Hangler countdown

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.