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