Android Progress Bar Learning A

Source: Internet
Author: User

Dolengthywork.java

 Packagetw.android;ImportJava.util.Calendar;ImportAndroid.os.Handler;ImportAndroid.widget.ProgressBar; Public classDolengthyworkextendsThread {PrivateHandler Mhandler;//Object Mhandler The work used to run the post update ProgressBar    PrivateProgressBar Mprobar;//This object is used to store the ProgressBar to be used for processing.//used to read the loop of the system time and continue post update ProgressBar work.      Public voidrun () {Calendar begin= Calendar.getinstance ();//time to read the system         Do{Calendar now=calendar.getinstance (); Final intidiffsec = * (Now.get (Calendar.minute)-Begin.get (Calendar.minute)) +now.get (Calendar.second)-Begin.get (Calendar.second); if(IDIFFSEC * 2 > 100) {Mhandler.post (NewRunnable () { Public voidrun () {mprobar.setprogress (100);                                }                });  Break; } mhandler.post (NewRunnable () { Public voidrun () {mprobar.setprogress (idiffsec* 2);                        }            }); if(IDIFFSEC * 4 < 100) Mhandler.post (NewRunnable () { Public voidrun () {mprobar.setsecondaryprogress (idiffsec* 4);            }                }); ElseMhandler.post (NewRunnable () { Public voidrun () {mprobar.setsecondaryprogress (100);        }                }); }  while(true); }        voidSetprogressbar (ProgressBar probar) {Mprobar=Probar; }        voidSetHandler (Handler h) {Mhandler=h; }}

Main.java

 Packagetw.android;Importandroid.app.Activity;ImportAndroid.os.Bundle;ImportAndroid.os.Handler;ImportAndroid.widget.ProgressBar; Public classMainextendsActivity {PrivateHandler Mhandler =NewHandler (); /**Called when the activity is first created.*/@Override Public voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.main);    Setupviewcomponent (); }        Private voidsetupviewcomponent () {//getting interface elements from the resource category R        FinalProgressBar Probar =(ProgressBar) Findviewbyid (R.ID.PROBAR2); Dolengthywork Work=Newdolengthywork ();        Work.sethandler (Mhandler);        Work.setprogressbar (Probar);    Work.start (); }}

A handler object is created in Mina.java, and two objects are set within setupviewcomponent ().

Android Progress Bar Learning A

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.