如何让不让AlertDialog dismissed by google search
?
google? search 键可以导致dialog? dismiss,虽然大多real device没有这个键,但还是预防为好。?
.setOnKeyListener(new DialogInterface.OnKeyListener() {
?
? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
? ? ? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? ? ? if(event.getKeyCode() == KeyEvent.KEYCODE_SEARCH){
? ? ? ? ? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })
?
?
例如:
?
?
new AlertDialog.Builder(YyBackUp.this)
? ? ? ? ? ? ? ? ? ? ? ? ? ? .setOnKeyListener(new DialogInterface.OnKeyListener() {
?
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public boolean onKey(DialogInterface dialog, int keyCode,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? KeyEvent event) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? // TODO Auto-generated method stub
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? if (event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return true;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? return false;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ? ? ? ? ? .setTitle(R.string.main_recovery_all)
? ? ? ? ? ? ? ? ? ? ? ? ? ? .setMessage(R.string.msg_recoverys_all)
? ? ? ? ? ? ? ? ? ? ? ? ? ? .setPositiveButton(R.string.dialog_ok,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new DialogInterface.OnClickListener() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog, int which) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? removeDialog(DIALOG_RECOVERY_ALL);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dialog.dismiss();
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? showSdcardSelectDialog(9);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? ? ? ? ? ? ? ? ? ? ? .setNegativeButton(R.string.dialog_cancel,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? new DialogInterface.OnClickListener() {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? public void onClick(DialogInterface dialog, int which) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? removeDialog(DIALOG_RECOVERY_ALL);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }).show();
http://blog.csdn.net/kufeiyun/archive/2011/01/22/6158581.aspx
http://www.liuzhaocn.com/?p=529同类参考