(reproduced) Android Common Dialog dialog box usage

Source: Internet
Author: User

Android Common Use of Dialog dialog box

There are many versions of Android that are usually developed when the dialog box is mostly used by custom or Google-provided V4,

The V7 Compatibility Pack is developed to keep the various versions of the dialog box style uniform, so this is used in the Alertdialog in the V7 package.

  1 Import Android.app.ProgressDialog;  2 Import Android.content.DialogInterface;  3 Import Android.os.Bundle;  4 Import Android.os.SystemClock;  5 Import Android.support.v7.app.AlertDialog;  6 Import android.support.v7.app.AppCompatActivity;  7 Import Android.view.View;  8 Import Android.widget.Toast; 9 public class Mainactivity extends appcompatactivity {one @Override protected void OnCreate (Bundle sav     Edinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); 16         } 17 18/** 19 * Normal dialog box * * @param view * * * CLICK1 (view view) {24 Alertdialog.builder Builder = new Alertdialog.builder (this); 25//Set title Builder.settitle ("User Safety tip:"); 27//Set prompt message Builder.setmessage ("Are you sure you accept the user's privacy policy?"); Builder.setpositivebutton ("OK", null); Builder.setnegativebutton ("Cancel", null); 31//Display Dialog BuiLder.show (); 33} 34 35/** 36 * Single-Select dialog box * * * * @param VIEW * * * * * * CLICK2 (view view) { Alertdialog.builder Builder = new Alertdialog.builder (this); 42//Set title Builder.settitle ("Choose one of your majors:"); 44//Set the item entry to display in the final String items[] = {"Java", "C + +", "PHP", "Android", "C #", "Python", "MYSQL"};             46//Set Item Click event Builder.setsinglechoiceitems (items,-1, New Dialoginterface.onclicklistener () {48 @Override-public void OnClick (Dialoginterface dialog, int which) {Toast.maketex T (mainactivity.this, "You have selected:" + Items[which], toast.length_short). Show (); Wuyi Dialog.dismiss (); 52} 53}); 54//Display Dialog builder.show (); 56} 57 58/** 59 * Multi-Select dialog box * @param view * */Click3 public void (view view) { Alertdialog.builder Builder = new Alertdialog. Builder (this); 65//Set title Builder.settitle ("Choose your Hobbies:"); 67//Set the item entry to be displayed in the final String items[] = {"Reading books", "Playing games", "Watching movies", "playing", "fitness", "Self-driving Tour", "Go to the Bar"}; 69//Set the selection status of each entry to False to not check true for checked final boolean[] checks = {True, True, False, False, False, False, F Alse}; 71//Set item Click to change the Boolean value in checks when the event entry is selected Builder.setmultichoiceitems (items, checks, new DIALOGINTERFAC E.onmultichoiceclicklistener () {@Override of the public void OnClick (Dialoginterface dialog, int w Hich, Boolean isChecked) {Checks[which] = isChecked; 76} 77});             78//Set OK button click event Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {80  @Override bayi public void OnClick (Dialoginterface dialog, int which) {StringBuffer buffer = New StringBuffer ();       for (int i = 0; i < checks.length; i++) {84              if (Checks[i]) {buffer.append (Items[i] + ","); 86} 87 } toast.maketext (Mainactivity.this, buffer.tostring (), Toast.length_short). Show (); 89} 90}); Builder.setnegativebutton ("Cancel", null); 92//Display dialog builder.show (); 94} 95 96/** 97 * Progress Bar Dialog 98 * @param view100 */101 public void Click4 (view view) { 102 Final ProgressDialog Dialog = new ProgressDialog (this); 103 Dialog.settitle ("Please wait:"); 104//dialo G.setmessage ("Trying to load ...");//dialog.show (); 106 107//The following property does not set the progress bar style by default to round 108 109//Set progress maximum of 10011 0 Dialog.setmax (100); 111//Set progress bar style for horizontal dialog.setprogressstyle (progressdialog.style_horizontal); 113 Dialog.show (); 115//Simulate a progress loading process the new Thread () {117 @Override118 P   ublic void Run () {119              for (int i = 0; I <=; i++) {dialog.setprogress (i); 121//Hugh             Sleep 200 milliseconds 122 systemclock.sleep (123)}124 Dialog.dismiss (); 125 }126}.start (); 127}128}

Category: Android control good text to the top of the attention I collect the article what is called the Beast
Follow-0
Fans-3 + plus attention00? Previous: Activity life cycle Detailed
? Next: detailed use of JDBC

(reproduced) Android Common Dialog dialog box usage

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.