How does Android Close the Alertdialog.builder dialog box? The Alertdialog.builder dialog box does not have a method like finish () or dismiss ().
But its parent class Alertdialog has a dismiss method, and Alertdialog.builder will get a Alertdialog object in the. Show (), and we can use the dismiss method to turn the builder off.
Alertdialog.builder Builder = new Alertdialog.builder (this);
Alertdialog dialog = Builder.show ();
About Android block Alertdialog shutdown The specific code looks like this:
Alertdialog.builder Builder = new Alertdialog.builder (getactivity ());
Builder.settitle ("test");
Layoutinflater inflater = getactivity (). Getlayoutinflater ();
View view = Inflater.inflate (r.layout.dialogfragment_num_input, NULL);
Builder.setview (view); Builder.setpositivebutton (OK), new Dialoginterface.onclicklistener () {@Override public void OnClick (dialoginterface dialog, int id) {Field field = null; try {//Get the Private property in dialog by reflection mshowing Field = Dialog.getclass (). Getsuperclass (). getdecl
Aredfield ("mshowing");
Field.setaccessible (TRUE);/Set this property to access the} catch (Exception ex) {} String Inputvalue = string.valueof (Medit.gettext ()); if (Inputvalue = null | |
"". Equals (Inputvalue)) {try {//Set Dialog not close Field.set (dialog, false);
Dialog.dismiss (); ' Catch (Exception ex) {}} ' else {////Do your own thing//try {//Close Field.set (dialog, True); Dialog.dismiss ();} catch (Exception
ex) {}}}}); Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {@Override public void OnClick (DialoginterfAce dialog, int id) {field Field = null; try {//Gets the private property in dialog by reflection mshowing Field = Dialog.getclass (). Getsuperclass (). Get
Declaredfield ("mshowing"); Field.setaccessible (TRUE);/Set this property to access the} catch (Exception ex) {} try {Field.set (dialog, True); Dialog.dismiss (); catch (Exception ex)
{
}
}
}); Builder.create ();