Android Common Dialog Box and android dialog box

Source: Internet
Author: User

Android Common Dialog Box and android dialog box
1. Dialog Box Notification)

You can use a dialog box to display a progress bar or confirm the information of your application.

The following code opens a dialog box:

Public void click1 (View view) {AlertDialog. builder builder = new Builder (this); builder. setTitle ("School of Engineering 1"); builder. setIcon (R. drawable. ic_launcher); builder. setMessage ("Browse wuyudong's blog? "); Builder. setPositiveButton ("OK", new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {Uri uri = Uri. parse ("http://www.wuyudong.com/"); // open the link Intent intent = new Intent (Intent. ACTION_VIEW, uri); startActivity (intent) ;}}); builder. setNegativeButton ("cancel", new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {dialog. cancel () ;}}); AlertDialog dialog = builder. create (); dialog. show ();}

URL: http://www.cnblogs.com/wuyudong/p/5854896.html.

2. Create a dialog box with a single option list
Public void click2 (View view) {AlertDialog. builder builder = new Builder (this); builder. setTitle ("single choice dialog box"); final String [] items = new String [] {"java ",". net "," php "}; builder. setSingleChoiceItems (items, 0, new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {Toast. makeText (MainActivity. this, items [which] + "clicked", 0 ). show () ;}}); builder. show ();}

3. Create a dialog box with multiple options
Public void click3 (View view) {AlertDialog. builder builder = new Builder (this); builder. setTitle ("Multi-choice dialog box"); final String [] items = new String [] {"java ",". net "," php "," C ++ "}; builder. setMultiChoiceItems (items, new boolean [] {true, false, false, true}, new OnMultiChoiceClickListener () {@ Override public void onClick (DialogInterface dialog, int which, boolean isChecked) {Toast. makeText (MainActivity. this, items [which] + isChecked, 0 ). show () ;}}); builder. setNegativeButton ("cancel", new OnClickListener () {@ Override public void onClick (DialogInterface dialog, int which) {dialog. cancel () ;}}); builder. show ();}

4. Progress dialog box (ProgressDialog)

Use the code ProgressDialog. show (ProgressDialogActivity. this, "Please wait", "data loading...", true); Create and display a progress dialog box.
Call setProgressStyle () to set the style of the Progress dialog box. There are two styles:
ProgressDialog. STYLE_SPINNER progress bar style (default style)
ProgressDialog. STYLE_HORIZONTAL horizontal progress bar style

Public void click4 (View view) {ProgressDialog pd = new ProgressDialog (this); pd. setTitle ("Reminder"); pd. setMessage ("loading ...... "); pd. show ();}

The following code implements the horizontal progress bar style:

    public void click5(View view) {        final ProgressDialog pd = new ProgressDialog(this);        pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);        pd.setMax(100);        pd.show();        new Thread() {            public void run() {                for (int i = 0; i < 100; i++) {                    pd.setProgress(i);                    try {                        Thread.sleep(20);                    } catch (InterruptedException e) {                        e.printStackTrace();                    }                }                pd.dismiss();            };        }.start();    }

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.