Apps for Android in ProgressDialog

Source: Internet
Author: User

Following the implementation of the Click button to display the loading box, 2 seconds after the automatic disappearance.

1. First add a button to the layout xml:

<Button Android:id="@+id/button1"Android:layout_width="wrap_content"Android:layout_height="wrap_content"Android:layout_alignparentleft="true"Android:layout_alignparenttop="true"Android:layout_marginleft="32DP"Android:layout_margintop="14DP"Android:background="@drawable/button_style"Android:text="@string/btntext"/>

2, add the View.onclicklistener event in the background Java code, rewrite the onclick, the code is as follows:

   Processbutton = (Button) Findviewbyid (r.id.button1);   Processbutton.setonclicklistener (myonclicklister);
View.onclicklistener Myonclicklister =NewView.onclicklistener () { Public voidOnClick (View v) {final ProgressDialog prodialog= Android.app.ProgressDialog.show (mainactivity. This,"Test","automatically disappears after 2 seconds! "); Thread Thread=NewThread () { Public voidrun () {Try{sleep ( -); } Catch(interruptedexception e) {//TODO Auto-generated catch blockE.printstacktrace (); } Prodialog.dismiss ();//This sentence must not be less, otherwise the program will be stuck dead.                  }             };          Thread.Start (); }     };

3, so the use of the thread of the sleep method to achieve. It is important to note, however, that the dismiss () method of the dialog object must be called at the end of the thread, or the program will go into the dead loop. The card died there.

4, the effect came out, is this:

Apps for Android in ProgressDialog

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.