Java Class Code:
1 //Normal progress dialog box2 Public voidBt8_onclick (View v)3 {4 FinalProgressDialog ProgressDialog =NewProgressDialog ( This);5Progressdialog.setmessage ("Please wait ...");6Progressdialog.settitle ("Progress dialog box");7Progressdialog.setcancelable (false);8 progressdialog.show ();9 //do not write business codeTen //Turn on child threads One //implementing Multithreading: 1. Inheritance 2. Implementing Interfaces A //1. Inherit the thread, rewrite the Run method, and then call the Start () method - NewThread () { - @Override the Public voidRun () {//{} indicates inheritance - //Business code - Try { - //Deferred thread +Thread.Sleep (3000); - } + Catch(Exception e) A { at - } - //Execute business code - //Close - Progressdialog.dismiss (); - } in}.start ();//{}start is responsible for starting child threads and automating the Run () method - } to //Horizontal Progress dialog box + Public voidBt9_onclick (View v) - { the FinalProgressDialog ProgressDialog =NewProgressDialog ( This); *Progressdialog.settitle ("Horizontal Progress dialog box"); $Progressdialog.setmessage ("Loading ...");Panax NotoginsengProgressdialog.setcancelable (false); - //Set as horizontal the Progressdialog.setprogressstyle (progressdialog.style_horizontal); + progressdialog.show (); A the FinalTextView tv_2 =(TextView) Findviewbyid (r.id.tv_2); + - //Start a child thread Internship Interface Runnable,run () $ NewThread (NewRunnable () { $ @Override - Public voidrun () { - //Simulate progress changes the for(inti = 0; I <=100; i++){ - progressdialog.setprogress (i);Wuyi Try { the //Deferred thread -Thread.Sleep (200); Wu } - Catch(Exception e) About { $ - } - } - //Accessing the view of the UI thread thread the child line ARunonuithread (NewRunnable () { + @Override the Public voidrun () { - $Tv_2.settext ("Download Complete"); the } the }); the Progressdialog.dismiss (); the } - }). Start (); in}
Notice how to turn on multithreading
Attached Mind map:
android--Progress dialog box