About Android Development Implementation progress Bar dialog box

Source: Internet
Author: User

The progress Bar dialog (ProgressDialog) is divided into two types: circular and horizontal.

Method:

Oncreatdialog (int id); Creates a dialog box that executes only when the dialog that the ID identifies is created the first time

Oncreatdialog (int id,bundle args); ibid., with parameters

Onpreparedialog (int id,dialog Dialog), after Oncreatedialog, each time the dialog box is displayed before it is executed

Onpreparedialog (int id,dialog dialog,bundle args); ibid., with parameters

ShowDialog (int id); Display dialog box

ShowDialog (int id,bundle args); Display dialog box with parameter

DismissDialog (int id), Hide dialog box, do not remove from activity, hold state

Add two buttons to layout. The first ID is set to Click_1, the second ID of the circular progress bar is set to Click_2, and the horizontal progress bar is displayed

1<?xml version="1.0"encoding="Utf-8"?>2<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"3Android:layout_width="match_parent"4android:layout_height="match_parent"5android:orientation="Vertical">6 7<Button8Android:id="@+id/click_1"9Android:layout_width="wrap_content"Tenandroid:layout_height="wrap_content" Oneandroid:text="Round progress bar"/> A  -<Button -Android:id="@+id/click_2" theAndroid:layout_width="wrap_content" -android:layout_height="wrap_content" -android:text="Horizontal progress bar"/> -  +</LinearLayout>
Layout Content

In the. java file

1 Package Lianxi;2 3 import Com.example.jichu_lianxi. R;4 5 import Android.accounts.OnAccountsUpdateListener;6 import android.app.Activity;7 import Android.app.Dialog;8 import Android.app.ProgressDialog;9 import Android.content.DialogInterface;Ten import Android.os.Bundle; One import Android.view.View; A import Android.view.View.OnClickListener; - import Android.widget.Button; - import Android.widget.Toast; the  -  Public classKeyonclick extends activity{ -     PrivateButton click_1; -     PrivateButton click_2; +     PrivateProgressDialog Mpdialog; -     Private intFlag =0; + @Override A     protected voidonCreate (Bundle savedinstancestate) { at         //TODO auto-generated Method Stub - super.oncreate (savedinstancestate); - Setcontentview (r.layout.key); -          -Click_1 =(Button) Findviewbyid (r.id.click_1); -Click_2 =(Button) Findviewbyid (r.id.click_2); in          -Click_1.setonclicklistener (NewOnclicklistener () { to              + @Override -              Public voidOnClick (View v) { the                 //TODO auto-generated Method Stub *Mpdialog =NewProgressDialog (Keyonclick. This); $                 //set the style of the Circle progress barPanax Notoginseng Mpdialog.setprogressstyle (progressdialog.style_spinner); -Mpdialog.settitle ("Tips");//Set Title the                 //Mpdialog.seticon (R.drawable.icon); //Set icon +Mpdialog.setmessage ("This is a circular progress bar .");//Set Content AMpdialog.setindeterminate (false);//set whether the progress bar can be ambiguous theMpdialog.setcancelable (true);//sets whether the progress bar can be canceled +Mpdialog.setbutton ("Determine",NewDialoginterface.onclicklistener () { -                      $ @Override $                      Public voidOnClick (Dialoginterface Dialog,intwhic) { -                         //TODO auto-generated Method Stub -Dialog.cancel ();//Cancel the                     } -                 });WuyiMpdialog.show ();//Show progress bar the             } -         }); Wu          -Click_2.setonclicklistener (NewOnclicklistener () { About              $ @Override -              Public voidOnClick (View v) { -                 //TODO auto-generated Method Stub -Flag =0; AMpdialog =NewProgressDialog (Keyonclick. This); +                 //set the horizontal progress bar style the Mpdialog.setprogressstyle (progressdialog.style_horizontal); -Mpdialog.settitle ("Tips");//Set Title $                 //Mpdialog.seticon (R.drawable.icon); //Set icon theMpdialog.setmessage ("This is the horizontal progress bar .");//Set Content theMpdialog.setmax ( -);  theMpdialog.setprogress (0); theMpdialog.setsecondaryprogress ( -); -Mpdialog.setindeterminate (false);//set whether the progress bar can be ambiguous inMpdialog.setcancelable (true);//sets whether the progress bar can be canceled theMpdialog.setbutton ("Determine",NewDialoginterface.onclicklistener () { the                      About @Override the                      Public voidOnClick (Dialoginterface Dialog,intwhic) { the                         //TODO auto-generated Method Stub theDialog.cancel ();//Cancel +                     } -                 }); the                 NewThread () {Bayi                      Public voidrun () { the                         Try{ the                              while(flag<= -)  -                             { -Mpdialog.setprogress (flag++); theThread.Sleep ( -); the                             } the Mpdialog.cancel (); the                             } -                         Catch(Exception e) the                         { the Mpdialog.cancel (); the                             94                         } the                     } the }.start (); theMpdialog.show ();//Show progress bar98             } About         }); -     }101}
Code

About Android Development Implementation progress Bar dialog box

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.