Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 331
Hoochwo Avatar asked Jun 01 '11 11:06

Hoochwo


1 Answers

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;
    }
});
}
like image 98
Hoochwo Avatar answered Oct 24 '22 12:10

Hoochwo