Learn about Android together create simple ProgressDialog (30)

Source: Internet
Author: User



See the following code:


public class Progressactivity extends Activity implements Onclicklistener {//MAX progress private static final int max_progress = 100;//progress bar Private ProgressDialog progressdialog;//Current progress value private int progress = 0;//control Private Button Btn_progress_1;priva Te Button btn_progress_2;private Handler Handler = new Handler () {@Overridepublic void Handlemessage (Message msg) {Super.h Andlemessage (msg); switch (msg.what) {case 1:if (Progress > Max_progress) {//reach maximum progress = 0;progressdialog.dismiss ();} else {progress++;//Progress increment 1progressdialog.incrementprogressby (1); handler.sendemptymessagedelayed (1,50 + new Random (). Nextint (500));} Break;default:break;}}; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( r.layout.activity_progress); Initviews (); Initlisteners ();} private void Initviews () {btn_progress_1 = (button) Findviewbyid (r.id.btn_progress_1); btn_progress_2 = (Button) Findviewbyid (r.id.btn_progress_2);} private void Initlisteners () {Btn_progresS_1.setonclicklistener (this); Btn_progress_2.setonclicklistener (this);} /** * Show dialog box */@SuppressWarnings ("deprecation") private void Showprogressdialog (int style) {ProgressDialog = new ProgressDialog (This);p Rogressdialog.seticon (r.drawable.ic_launcher);p rogressdialog.settitle ("Processing data ..."); Progressdialog.setmessage ("Please later ...");//Set the style of the progress dialog box Progressdialog.setprogressstyle (style);// Sets the progress maximum of the progress dialog box Progressdialog.setmax (max_progress);//Set the pause button for the Progress dialog box Progressdialog.setbutton ( Dialoginterface.button_positive, "Pause", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick ( Dialoginterface dialog, int which) {handler.removemessages (1);}}); /Set Progress Dialog "Cancel" button Progressdialog.setbutton (dialoginterface.button_neutral, "Cancel", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {handler.removemessages (1);//Reset progress = 0; Progressdialog.setprogress (progress);}}); Progressdialog.show ();p rogress = (Progress > 0)? Progress:0;progressdialog.setprogress(progress); Handler.sendemptymessage (1);} @Overridepublic void OnClick (View v) {switch (V.getid ()) {Case r.id.btn_progress_1://Progress dialog Box Showprogressdialog ( progressdialog.style_horizontal) break;case r.id.btn_progress_2://Rotation dialog showprogressdialog (ProgressDialog.STYLE_ SPINNER); break;default:break;}}}




Reprint Please specify source:http://blog.csdn.net/hai_qing_xu_kong/article/details/45024997 Emotional Control _

Learn about Android together create simple ProgressDialog (30)

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.