Learning notes for Android: progressdialog

Source: Internet
Author: User

mian. xml

<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> Android: Orientation = "vertical"> <br/> <textview <br/> Android: id = "@ + ID/Information" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "progressdialog"/> <br/> <button <br/> Android: Id = "@ + ID/button1" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "circle"/> <br/> <button <br/> Android: Id = "@ + ID/button2" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: text = "horizontal bar"/> </P> <p> </linearlayout>

 

Java:

Package android2.test; </P> <p> Import android. app. activity; <br/> Import android. app. progressdialog; <br/> Import android. content. dialoginterface; <br/> Import android. OS. bundle; <br/> Import android. view. view; <br/> Import android. widget. button; </P> <p> public class android2activity extends activity {<br/> private button button1, button2; </P> <p> int m_count = 0; <br/> // progress bar declaration dialog box <br/> progressdialog progres Sdialog; </P> <p> @ override <br/> Public void oncreate (bundle savedinstancestate) <br/>{< br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); </P> <p> // obtain the button object <br/> button1 = (button) findviewbyid (R. id. button1); <br/> button2 = (button) findviewbyid (R. id. button2); </P> <p> // set the event listening for button1 <br/> button1.setonclicklistener (New button. onclicklistener () {<br/> Public void onclick (View V) <br/> {<br/> // todo auto-generated method stub </P> <p> // create a progressdialog object <br/> progressdialog = new progressdialog (android2activity. this); </P> <p> // set the progress bar style, which is circular and rotated. <br/> progressdialog. setprogressstyle (progressdialog. style_spinner); </P> <p> // set the progressdialog title <br/> progressdialog. settitle ("prompt"); </P> <p> // set progressdialog prompt information <br/> progressdialog. setmessage ("buffering... please wait ..... "); </ P> <p> // set the progressdicon title icon <br/> // m_pdialog.seticon (R. drawable. img1); </P> <p> // set whether the progress bar of progressdialog is clear <br/> progressdialog. setindeterminate (false); </P> <p> // sets whether progressdialog can be canceled by pressing the return button. <br/> progressdialog. setcancelable (true); </P> <p> // set a button for progressdialog <br/> progressdialog. setbutton ("OK", new dialoginterface. onclicklistener () {<br/> Public void onclick (dialoginterface dialo G, int I) <br/>{< br/> // click "OK" to cancel the dialog box <br/> dialog. cancel (); <br/>}< br/>}); </P> <p> // display progressdialog <br/> progressdialog. show (); <br/>}< br/>}); </P> <p> // set event listening for button2 <br/> button2.setonclicklistener (New button. onclicklistener () {<br/> Public void onclick (view V) <br/> {<br/> // todo auto-generated method stub </P> <p> m_count = 0; </P> <p> // create a progressdialog object <br/> progressdialog = N EW progressdialog (android2activity. this); </P> <p> // set the progress bar style. The style is long. <br/> progressdialog. setprogressstyle (progressdialog. style_horizontal); </P> <p> // set the progressdialog title <br/> progressdialog. settitle ("prompt"); </P> <p> // set progressdialog prompt information <br/> progressdialog. setmessage ("buffering... please wait ..... "); </P> <p> // set the progressdicon title icon <br/> // m_pdialog.seticon (R. drawable. img2); </P> <p> // sets the progress bar of progressdialog. <br /> Progressdialog. setprogress (100); </P> <p> // set whether the progress bar of progressdialog is clear <br/> progressdialog. setindeterminate (false); </P> <p> // sets whether progressdialog can be canceled by pressing the return button. <br/> progressdialog. setcancelable (true); </P> <p> // display progressdialog <br/> progressdialog. show (); </P> <p> New thread () <br/> {<br/> Public void run () <br/>{< br/> try <br/>{< br/> while (m_count <= 100) <br/>{< br/> // The progress is controlled by the thread. <Br/> progressdialog. setprogress (m_count ++); <br/> thread. sleep (100); <br/>}< br/> progressdialog. cancel (); <br/>}< br/> catch (interruptedexception e) <br/>{< br/> progressdialog. cancel (); <br/>}< br/> }. start (); </P> <p >}< br/>}); <br/>}< br/>

Related Article

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.