Android Common dialog box

Source: Internet
Author: User

1.dialog box notification (Dialog Notification)

You can use a dialog box when your app needs to display a progress bar or if the user needs to confirm the information.

The following code opens a dialog box:

     Public voidclick1 (view view) {Alertdialog.builder Builder=NewBuilder ( This); Builder.settitle ("Engineering Building No. 1th");        Builder.seticon (R.drawable.ic_launcher); Builder.setmessage ("Browse Wuyudong's blog?" )); Builder.setpositivebutton ("OK",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {URI Uri= Uri.parse ("http://www.wuyudong.com/");//Open LinkIntent Intent =NewIntent (Intent.action_view, URI);            StartActivity (Intent);        }        }); Builder.setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)            {Dialog.cancel ();        }        }); Alertdialog Dialog=builder.create ();    Dialog.show (); }

This article address: http://www.cnblogs.com/wuyudong/p/5854896.html, reprint please indicate source address.

2. Create a dialog box with a list of single options
     Public voidClick2 (view view) {Alertdialog.builder Builder=NewBuilder ( This); Builder.settitle ("Radio dialog box"); Finalstring[] Items =NewString[] {"Java", ". Net", "PHP" }; Builder.setsinglechoiceitems (Items,0,NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich) {Toast.maketext (mainactivity). This, Items[which] + "clicked", 0). Show ();        }        });    Builder.show (); }

3. Create a dialog box with a multi-option list
     Public voidClick3 (view view) {Alertdialog.builder Builder=NewBuilder ( This); Builder.settitle (Multi-Select dialog box); Finalstring[] Items =NewString[] {"Java", ". Net", "PHP", "C + +" }; Builder.setmultichoiceitems (Items,New Boolean[] {true,false,false,                true},NewOnmultichoiceclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich,BooleanisChecked) {Toast.maketext (mainactivity). This, Items[which] + isChecked, 0). Show ();        }        }); Builder.setnegativebutton ("Cancel",NewOnclicklistener () {@Override Public voidOnClick (Dialoginterface Dialog,intwhich)            {Dialog.cancel ();        }        });    Builder.show (); }

4.Progress dialog box (ProgressDialog)

Use code progressdialog.show (progressdialogactivity.this, "Please Wait", "data is loading ...", true); Create and display a progress dialog box.
Call the Setprogressstyle () method to set the progress dialog box style. There are two types of styles:
Progressdialog.style_spinner Rotation progress bar style (default style)
Progressdialog.style_horizontal Horizontal progress bar Style

     Public void Click4 (view view) {        new progressdialog (this);        Pd.settitle ("Reminder");        Pd.setmessage ("Loading in ...");        Pd.show ();    }

The following code implements the horizontal progress bar style:

     Public voidclick5 (view view) {FinalProgressDialog PD =NewProgressDialog ( This);        Pd.setprogressstyle (progressdialog.style_horizontal); Pd.setmax (100);        Pd.show (); NewThread () { Public voidrun () { for(inti = 0; I < 100; i++) {pd.setprogress (i); Try{Thread.Sleep (20); } Catch(interruptedexception e) {e.printstacktrace ();            }} Pd.dismiss ();        };    }.start (); }

Android Common 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.