Alertdialog.builder builder = new Builder (this);
Builder.create (). Show ();
The dialog box is displayed so that the dialog can be closed when the user presses the back or search key.
How to implement a dialog box similar to that on a Windows system, you must click the button on the dialog box to close the dialog box.
Here is the specific code:
Alertdialog.builder builder = new Builder (this);
Builder.setmessage (msg);
Builder.settitle (title);
Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {
public void OnClick (Dialoginterface dialog, int which)
{
Dialog.dismiss ();
}
});
Alertdialog Alertdialog = Builder.create ();
alertdialog.setcancelable (false); Setting this dialog box cannot be canceled by the user by pressing [Return key], but the test finds that if the user presses Keyevent.keycode_search, the dialog box will be dismiss off.
Due to setting alertdialog.setcancelable (false); found that if the user pressed the Keyevent.keycode_search, the dialog box will still be dismiss off, the setonkeylistener role here is to block the user press Keyevent.keycode_search
Alertdialog.setonkeylistener (New Dialoginterface.onkeylistener () {
@Override
public boolean OnKey (dialoginterface dialog, int keycode, keyevent event)
{
if (keycode = = Keyevent.keycode_search)
{
return true;
}
Else
{
return false; Default return False
}
}
});
Alertdialog.show ();
2012-01-03
Android: Create a alertdialog dialog box, you must press the OK or Cancel button to close the dialog box, do not press [back] or [search key] to close