Reproduced in http://blog.csdn.net/csh159/article/details/8127280
Using the reflection mechanism in Java:
dialog = new Alertdialog.builder (mainactivity.this);
Dialog.settitle ("Enter user name:");
Dialog.setpositivebutton ("Start",
New Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialogq, int which) {
Field field;
try {
field = Dialogq.getclass (). Getsuperclass ()
. Getdeclaredfield ("mshowing");
Field.setaccessible (TRUE);
Set the mshowing value to spoof the Android system
Field.set (Dialogq, false);//If True, it will be launched
} catch (Nosuchfieldexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (IllegalArgumentException e) {
TODO auto-generated Catch block
E.printstacktrace ();
} catch (Illegalaccessexception e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
}
});
Dialog.setnegativebutton ("Stop", new Dialoginterface.onclicklistener () {
@Override
public void OnClick (Dialoginterface dialog, int which) {
Dialog.cancel ();
}
});
Dialog.setview (linear);
Android Alertdialog Settings Click button do not exit (GO)