Android alertdialog Learning

Source: Internet
Author: User

1. There are two buttons in the dialog box

Builder = new alertdialog. builder (alertdialogactivity. this); builder. seticon (Android. r. drawable. btn_plus); builder. settitle ("btnplus"); builder. setmessage ("no? "); Builder. setpositivebutton ("OK", new dialoginterface. onclicklistener () {public void onclick (dialoginterface dialog, int which) {toast. maketext (alertdialogactivity. this, "you have selected the OK button", toast. length_short ). show () ;}}); builder. setnegativebutton ("cancel", new dialoginterface. onclicklistener () {public void onclick (dialoginterface dialog, int which) {toast. maketext (alertdialogactivity. this, "you have selected the cancel button", toast. length_short ). show () ;}}); builder. show ();}

2. Dialog Box with three buttons

Public void onclick (view v) {// todo auto-generated method stubnew alertdialog. builder (alertdialogactivity. this ). seticon (Android. r. drawable. btn_star ). settitle ("tip "). setmessage ("prompt content, three buttons "). setpositivebutton ("OK", new dialoginterface. onclicklistener () {public void onclick (dialoginterface Diener, int which) {// todo auto-generated method stubtoast. maketext (alertdialogactivity. this, "you have selected the OK button", toast. length_short ). show ();}}). setneutralbutton ("menu", new dialoginterface. onclicklistener () {public void onclick (dialoginterface Diener, int which) {// todo auto-generated method stubtoast. maketext (alertdialogactivity. this, "you have selected the detail button", toast. length_short ). show ();}}). setnegativebutton ("cancel", new dialoginterface. onclicklistener () {public void onclick (dialoginterface dialog, int which) {toast. maketext (alertdialogactivity. this, "you have selected the cancel button", toast. length_short ). show ();}}). show ();}

3. dialog box that can be entered

Public void onclick (view v) {// todo auto-generated method stublayoutinflater Inflater = layoutinflater. from (alertdialogactivity. this); final view textentryview = Inflater. inflate (R. layout. alert_dialog_text_entry, null); Final edittext usernameet = (edittext) textentryview. findviewbyid (R. id. username_value); Final edittext passwordet = (edittext) textentryview. findviewbyid (R. id. password_value); New alertdialog. builder (alertdialogactivity. this ). seticon (Android. r. drawable. btn_star ). settitle ("tip "). setview (textentryview ). setpositivebutton ("OK", new dialoginterface. onclicklistener () {public void onclick (dialoginterface dialog, int which) {toast. maketext (alertdialogactivity. this, "username =" + usernameet. gettext (). tostring () + "\ n Password =" + passwordet. gettext (). tostring (), toast. length_short ). show ();}}). setnegativebutton ("cancel", new dialoginterface. onclicklistener () {public void onclick (dialoginterface dialog, int which) {toast. maketext (alertdialogactivity. this, "you have selected the cancel button", toast. length_short ). show ();}}). show ();


4. progress bar dialog box

Progressdialog dialog = new progressdialog (alertdialogactivity. This); dialog. settitle ("processing... "); Dialog. setmessage (" Please wait... "); Dialog. Show ();

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.