How to handle Back button with in the dialog?

后端 未结 8 2311
无人共我
无人共我 2020-11-30 01:02

I am developing an application that when the button is pressed, it opens a dialog with OK and Cancel buttons.

It works fine.

When the user presses the back b

8条回答
  •  旧时难觅i
    2020-11-30 01:37

    You need to override OnCancel method. This method calls on Back Key press. Here's code which works perfect to me.

     AlertDialog alertDialog;
    
        alertDialog.setOnCancelListener(new OnCancelListener() 
        {                   
               @Override
                public void onCancel(DialogInterface dialog) 
                 {
                   // TODO Auto-generated method stub
    
                        dialog.dismiss();                           
    
                }
    }); 
    

    Hope this will help you, and accept it if it is helpful to you.

    Thanks..

提交回复
热议问题