This article describes the usage of the Android AlertDialog dialog box. Share it for your reference, as follows:
Introduction to the AlertDialog dialog box
1. Obtain the static inner class Buidler object of AlertDialog, and use this class to create the AlertDialog object, because all the constructors of AlertDialog are of type Protected
2. Set the title, button and event to which the button of the dialog box should respond to through the Buidler object
3. Call Buidler's create() method to create a dialog box
4. Call AlterDialog's show() method to display the content
Method 1: Confirm dialog similar to HTML
//AlertDialog dialog boxpublic void createAlertDialog(){ builder = new (this); ("test AlertDialog"); ("yes", new () { @Override public void onClick(DialogInterface dialog, int which) { (getApplicationContext(), "Delete successfully", Toast.LENGTH_SHORT).show(); } }); ("no", new () { @Override public void onClick(DialogInterface dialog, int which) { (getApplicationContext(), "Delete Cancel", Toast.LENGTH_SHORT).show(); } }); ().show(); }
Method 2: Set multiple entry options like a context menu
//AlertDialog Sets entries with multiple options or single choicepublic void createAtherAlertDialog(){ // Since the construction method of AlertDialog is of protected type, you cannot directly new the object and must rely on the class builder = new (this); builder = ("Alert similar to menu"); String[] array = {"Baked Wings","abalone","Bear's Paw","Rubbish"}; boolean[] numbers = {false,false,false,false}; //The way to be commented is to implement single selection// (array, new (){ // @Override // public void onClick(DialogInterface dialog, int which) { // (which); // } // }); //The following method is to achieve multiple selection (array, numbers, new (){ @Override public void onClick(DialogInterface dialog, int which, boolean isChecked) { ("which : "+which + " isChecked : "+ isChecked); } }); ().show(); }
For more information about Android related content, please check out the topic of this site:Android file operation skills summary》、《A summary of SD card operation methods for Android programming and development》、《Android development introduction and advanced tutorial》、《Android resource operation skills summary》、《Android View View Tips Summary"and"Android control usage summary》
I hope this article will be helpful to everyone's Android programming design.