Android generates a prompt box

Source: Internet
Author: User

You can use Alertdialog.builder to generate a prompt box


The simplest thing to do is pop up a message box :

New Alertdialog.builder (self). Settitle ("title"). Setmessage ("Simple message box") . Setpositivebutton ("OK", null). Show ();

The effect is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/49/E8/wKiom1Qe4lHAXmZlAABWNVK03qE016.jpg "title=" Cheetah 20140921223514.png "alt=" Wkiom1qe4lhaxmzlaabwnvk03qe016.jpg "/>


dialog box with confirmation and Cancel buttons:

New Alertdialog.builder (self). Settitle ("yes"). Setmessage ("Yes? "). Setpositivebutton (" yes ", null). Setnegativebutton (" No ", null). Show ();


dialog boxes where you can enter text:

New Alertdialog.builder (self). Settitle ("Please enter text:"). SetIcon (Android. R.drawable.ic_dialog_info). Setview (new EditText (self)). Setpositivebutton ("OK", null). Setnegativebutton ("Cancel", null ). Show ();


Radio Box:

new alertdialog.builder (self)   .settitle ("Please select:")    .seticon (Android. R.drawable.ic_dialog_info)                    .setsinglechoiceitems (new string[] {"option 1", "Option 2", "option 3", "Option 4"}, 0,      new dialoginterface.onclicklistener ()  {                                       public void onclick ( Dialoginterface dialog, int which)  {           dialog.dismiss ();       }    }  )    .setnegativebutton ("Cancel",  null)   .show (); 


Multi Box:

New Alertdialog.builder (self). Settitle ("Multi Box"). Setmultichoiceitems (new string[] {"Option 1", "Option 2", "option 3", "Option 4"}, NULL, NULL). Setpositivebutton ("OK", null). Setnegativebutton ("Cancel", null). Show ();


List dialog box:

New Alertdialog.builder (self). Settitle ("list box"). Setitems (new string[] {"List item 1", "List item 2", "List Item 3"}, NULL). Setnegativebutton ("OK", null). Show ();


To display a picture in a dialog box:

ImageView img = new ImageView (self);  Img.setimageresource (R.drawable.icon); New Alertdialog.builder (self). Settitle ("picture box"). Setview (IMG). Setpositivebutton ("OK", null). Show ();


Event handling:


With a definite dialog box

New alertdialog.builder (This)          .setmessage ("This is the second hint")          .setpositivebutton ("OK",                           new dialoginterface.onclicklistener () {                                   public void onclick (dialoginterface dialoginterface,  Int i) {                                       //Button Event                                   }                           })          .show ();


dialog box with OK and cancel

New alertdialog.builder (This)         .settitle ("hint")          .setmessage ("OK exit?")         .seticon (r.drawable.quit)          .setpositivebutton ("OK",  new dialoginterface.onclicklistener ()  {         public void onclick (dialoginterface dialog, int  Whichbutton)  {        setresult (RESULT_OK);//OK button event          finish ();        }         })         .setnegativebutton ("Cancel",  new dialoginterface.onclicklistener ()  {        public  void onclick (Dialoginterface dialog, int whichbutton) &NBsp {         //Cancel button event          }        })         .show ();


This article is from the "Zifangsky" blog, make sure to keep this source http://983836259.blog.51cto.com/7311475/1556770

Android generates a prompt 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.