android--Progress dialog box

Source: Internet
Author: User

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

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.