How to avoid a DialogFragment being dismissed when the Search button is pressed - Android
After setting:
MyDialogFragment fragment = new MyDialogFragment();
fragment .setCancelable(false);
it is still dismissed after click on search button. and i haven't found option like in activity to override onKeyDown();
开发者_高级运维I need create dialog that will be shown until my "dismiss" button is pressed.Please Help
I've just found an answer. After DialogFragment was created we can get the its dialog
Dialog dialog = getDialog();
if( null!= dialog)
{
dialog.setOnKeyListener(new OnKeyListener()
{
@Override
public boolean onKey ( DialogInterface dialog , int keyCode , KeyEvent event )
{
// disable search button action
if (keyCode == KeyEvent.KEYCODE_SEARCH)
{
return true;
}
return false;
}
});
}
getFragmentManager().popBackStack();
Hope this helps!
精彩评论