Android Alertdialog Common use

Source: Internet
Author: User

Android Alertdialog Common use

Simple Prompt Box:

Alertdialog.builder Alertdialog = new Alertdialog.builder (this); Alertdialog.settitle ("HELLO"); Alertdialog.setmessage ("Hello,world"); Alertdialog.setpositivebutton ("OK", new Dialoginterface.onclicklistener () { @Overridepublic void OnClick (dialoginterface arg0, int arg1) {//TODO auto-generated method Stubtoast.maketext ( Getapplicationcontext (), "OK" + Arg1,toast.length_short). Show (); Arg0.dismiss ();}); Alertdialog.show ();

  

Confirm, Cancel Box:

Alertdialog.builder Alertdialog = new Alertdialog.builder (this); Alertdialog.settitle ("HELLO"); Alertdialog.setmessage ("is sure to delete?"); Alertdialog.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick ( Dialoginterface arg0, int arg1) {//TODO auto-generated method Stubtoast.maketext (Getapplicationcontext (), "OK" + arg1, to Ast. Length_short). Show (); Arg0.dismiss ();}); Alertdialog.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick ( Dialoginterface arg0, int arg1) {//TODO auto-generated method Stubtoast.maketext (Getapplicationcontext (), "Canceled" + Arg1, Toast.length_short). Show (); Arg0.dismiss ();}). Create (); Alertdialog.show ();

Single-selection list pop-up box:

Alertdialog.builder Alertdialog = new Alertdialog.builder (this); Alertdialog.settitle ("HELLO"); string[] items = new string[] {"123", "345"};alertdialog.setsinglechoiceitems (items, 0,new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface arg0, int arg1) {//TODO auto-generated Method Stubtoast.maketext (Getapplicationcontext (), "" + Arg1,toast.length_long). Show ();}); Alertdialog.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick ( Dialoginterface arg0, int arg1) {//TODO auto-generated method Stubtoast.maketext (Getapplicationcontext (), "OK" + arg1,to Ast. Length_short). Show (); Arg0.dismiss ();}); Alertdialog.show ();

Multiple list selection pop-up box:

Alertdialog.builder Alertdialog = new Alertdialog.builder (this); Alertdialog.settitle ("HELLO"); string[] items = new string[] {"123", "345"};alertdialog.setmultichoiceitems (items,new boolean[]{true,false},new Dialoginterface.onmultichoiceclicklistener () {@Overridepublic void OnClick (dialoginterface arg0, int Arg1,boolean ARG2) {//TODO auto-generated Method stub}}); Alertdialog.setpositivebutton ("OK", New Dialoginterface.onclicklistener ( {@Overridepublic void OnClick (dialoginterface arg0, int arg1) {//TODO auto-generated method Stubtoast.maketext (getappl Icationcontext (), "OK" + arg1, Toast.length_short). Show (); Arg0.dismiss ();}); Alertdialog.show ();

  

Android Alertdialog Common use

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.