Android ProgressDialog Loading Progress

Source: Internet
Author: User

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent" >5 6     <Button7         Android:layout_width= "Wrap_content"8 Android:layout_height= "Wrap_content"9 Android:onclick= "Progress"Ten Android:text= "ProgressDialog" /> One  A </Relativelayout>
1  Public classMainactivityextendsActivity {2 3 @Override4     protected voidonCreate (Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7     }8     9     /**Ten * ProgressDialog is a subclass of the Alertdialog class that displays a progress animation of the rotation wheel shape for a task that does not define progress, One * or display a progress bar for a task that specifies progress. It's very useful, and every time a user is working on a deferred task, we have to tell the user in the form of a progress dialog box. A * Otherwise the user does not know that the operation has started, may operate the same task multiple times, and may cause an exception to occur.  -      * @paramv -      */ the  -      Public voidProgress (View v) { -         FinalProgressDialog dialog =NewProgressDialog ( This); -Dialog.settitle ("Progress bar dialog box"); +Dialog.setmessage ("Loading ..."); -         //Dialog.setprogressstyle (progressdialog.style_spinner);//Rotating Wheel Progress +Dialog.setprogressstyle (progressdialog.style_horizontal);//Horizontal Load progress bar ADialog.setmax (200);//Default Value of at dialog.show (); -         NewThread () { -              Public voidrun () { -                 intindex = 0; -                  while(Index++ <Dialog.getmax ()) { - dialog.setprogress (index); in                     Try { -Thread.Sleep (100); to}Catch(interruptedexception e) { + e.printstacktrace (); -                     } the                 } *                 //load Complete Close dialog box $                 if(dialog!=NULL&&dialog.isshowing ()) {Panax Notoginseng Dialog.dismiss (); -                 } the             } + }.start (); A     } the}
mainactivity

Android ProgressDialog Loading Progress

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.