This example describes the Android Alertdialog dialog box usage. Share to everyone for your reference, specific as follows:
Introduction to the Alertdialog dialog box
1, get alertdialog static internal class Buidler object, the class to create Alertdialog objects, because the Alertdialog construction method is all protected type
2, through the Buidler object to set the dialog box title, button and button to respond to the event Dialoginterface.onclicklistener
3, call the Buidler Create () method Creation dialog box
4, call the Alterdialog Show () method to display the content
Mode one: HTML-like Confirm dialog box
Alertdialog dialog box public
void Createalertdialog () {
Alertdialog.builder Builder = new Alertdialog.builder (this );
Builder.setmessage ("Test Alertdialog");
Builder.setpositivebutton ("Yes", new Dialoginterface.onclicklistener () {
@Override public
void OnClick ( Dialoginterface dialog, int which) {
toast.maketext (Getapplicationcontext (), "Delete succeeded", Toast.length_short). Show ();
}
});
Builder.setnegativebutton ("No", new Dialoginterface.onclicklistener () {
@Override public
void OnClick ( Dialoginterface dialog, int which) {
toast.maketext (Getapplicationcontext (), delete Cancel, toast.length_short). Show () ;
}
});
Builder.create (). Show ();
Mode two: Set multiple entry options like context menu
//alertdialog set entries for multiple options or radio public void Createatheralertdialog () {//due to the construction of Alertdialog
method is protected type, so you cannot directly new this object, you must rely on Alertdialog.builder class Alertdialog.builder Builder = new Alertdialog.builder (this);
Builder = builder.settitle ("Alert similar to Menu");
String[] Array = {"Roast wing", "Abalone", "Bear's Paw", "rubbish"};
boolean[] numbers = {False,false,false,false}; The annotated way is to implement the radio//Builder.setitems (array, new Dialoginterface.onclicklistener () {//@Override//public void OnC
Lick (dialoginterface dialog, int which) {//SYSTEM.OUT.PRINTLN (which);//}//}); The following way is to implement multiple-selection builder.setmultichoiceitems (array, numbers, new Dialoginterface.onmultichoiceclicklistener () {@Overri De public void OnClick (Dialoginterface dialog, int which, Boolean ischecked) {System.out.println ("which
: "+which +" ischecked: "+ ischecked";
}
});
Builder.create (). Show (); }
For more information on Android-related content readers can view the site topics: "Android File Operation tips Summary", "Android programming development of the SD card operation Summary", "Android Development introduction and Advanced Course", "Android Resources Operating Skills summary", " Android View tips Summary and a summary of the use of Android controls
I hope this article will help you with the Android program.