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