1-Normal Progress dialog box
public void Bt_8 (View v) { final progressdialog progressdialog=new ProgressDialog (this); Progressdialog.settitle ("hint"); Progressdialog.setmessage ("Please wait ..."); Progressdialog.setcancelable (false);//prevent clicking elsewhere to close progressdialog.show (); Do not write business code //Open sub -thread//multithreading-inherit; Implement Interface //1-inherit Thread, override inside Method (run), call Start method new Thread () { @ Override public Void Run () { //delay thread try { thread.sleep (+); } catch (Exception e) { } //Open Direct close Progressdialog.dismiss (); } }. Start ();//responsible for starting a child thread, automatically executing the Run method }
View Code
2-Horizontal Progress dialog box
Public void Bt_9 (View v) {final ProgressDialog progressdialog=new progressdialog (this); Progressdialog.settitle ("Horizontal Progress dialog box"); Progressdialog.setmessage ("Loading ..."); Progressdialog.setcancelable (FALSE); Set into horizontal Progressdialog.setprogressstyle (progressdialog.style_horizontal); Progressdialog.show (); Final TextView tv_1= (TextView) Findviewbyid (r.id.tv_1); The way to start a child thread implements an interface Runnable, there is only one method (run) New Thread (new Runnable () {@Override public void run () {//Simulation progress change for (int i=0;i<=100; i++) {progressdialog.setprogress (i); Deferred thread try {thread.sleep (500); } catch (Exception e) {}}//In the child thread to access the UI thread's view Runonuithr EAD (New Runnable () {@Override public void run () {Tv_1.sette XT ("Download Complete"); } }); Turn the Progressdialog.dismiss directly off (); }}). Start (); }
View Code
Progress Bar dialog box