About Android Development using the Alertdialog Implementation dialog box

Source: Internet
Author: User

The Alertdialog class is powerful enough not only to generate a hint dialog with a button, but also to generate a dialog box with a list.

Using the Alertdialog Implementation dialog box
Build a layout file Alert.xml add a button named: displays a dialog box with the Cancel neutral OK button
Build an activity Alertdialog_lianxi.java
Add an event listener for the button

Add a button in layout

1 <button2         android:id="@+id/button1"3         android:layout_width="wrap_content"4         android:layout_height ="wrap_content"5         android:text=" display with Cancel. Neutral, OK button dialog box " />

Key code in activity

1 @Override2      Public voidOnClick (View v) {3         //TODO auto-generated Method Stub4         Switch(V.getid ()) {5          CaseR.id.button1:6Alertdialog.builder Builder =NewAlertdialog.builder (Alertdialog_lianxi. This);7Builder.settitle ("displays a dialog box with the Cancel neutral OK button");//setting the caption of a dialog box8Builder.setmessage ("here is the contents of the dialog box");//Setting the contents of a dialog box9             //Builder.seticon (r.drawable.icon_1); //Setting the icon for a dialog boxTen  One             //Add OK button ABuilder.setpositivebutton ("Determine",NewDialog.onclicklistener () { - @Override -                  Public voidOnClick (Dialoginterface Dialog,intwhich) { theToast.maketext (Alertdialog_lianxi. This,"you clicked the OK button", Toast.length_short). Show ();//Show toast message box -                 } -             }); -             //Add Cancel button +Builder.setnegativebutton ("Cancel",NewDialog.onclicklistener () { - @Override +                  Public voidOnClick (Dialoginterface Dialog,intwhich) { AToast.maketext (Alertdialog_lianxi. This,"you clicked the Cancel button", Toast.length_short). Show ();//Show toast message box at                 } -             }); -             //Add Neutral button -Builder.setneutralbutton ("Neutral",NewDialog.onclicklistener () { - @Override -                  Public voidOnClick (Dialoginterface Dialog,intwhich) { inToast.maketext (Alertdialog_lianxi. This,"you clicked the neutral button", Toast.length_short). Show ();//Show toast message box -                 } to             }); +Builder.create (). Show ();//Show dialog Box -              Break;

About Android Development using the Alertdialog Implementation dialog 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.