开发者

cancelListener vs keyListener

开发者 https://www.devze.com 2023-02-06 23:41 出处:网络
I want dismissDialog(ID) to be called whenever dialog is gone (disapears, get clos开发者_StackOverflowed , ...), so it may happen when user press BACK button or any other scenario that may close the d

I want dismissDialog(ID) to be called whenever dialog is gone (disapears, get clos开发者_StackOverflowed , ...), so it may happen when user press BACK button or any other scenario that may close the dialog.

which one is better approach? to call onCancelListener on dialog? or call OnKeyListener and assign if (keyCode == KeyEvent.KEYCODE_BACK) // do smth

thanks.


Use onBackPressed(), to do cleanup or whatever you want to do in dismissdialog()


if you do not ant to allow to dialog disappear,when back button pressed.it can be done by setting dialog's property as below:


dialog.setCancelable(false);//here dialog is object of Dialog class which you want to show
0

精彩评论

暂无评论...
验证码 换一张
取 消