Friday, March 2, 2012

Progress Dialog issue when clicking default search button in Android

When we are using a Non-cancelable progress dialog , There a chance to dismiss when a  when a user click in default search button of Anroid phone.. To prevent this , Override keylistner of the progress dialog and consume that event.
For example :

mDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
  @Override
  public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
    return true; // Pretend we processed it
   }
  return false; // Any other keys are still processed as normal
  }
});

No comments:

Post a Comment