如何处理后退按钮,在对话框中? [英] How to handle Back button with in the dialog?

查看:89
本文介绍了如何处理后退按钮,在对话框中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序。在这个当pressed我会打开一个对话框,点击确定和取消按钮的按钮。

它工作正常。

我的问题是之前打开时,用户preSS后退按钮我像处理的休耕

对话

 公共布尔的onkeydown(INT键code,KeyEvent的事件)
{
    如果((钥匙code == KeyEvent.KEY code_BACK))
    {

    }
 返回super.onKeyDown(键code,事件);
}
 

它的工作原理fine.But当用户打开对话框,preSS后退按钮,上面的方法没有被调用。

我该如何处理呢?

如果有任何人知道的解决方案,请帮助我。

在此先感谢

解决方案

  dialog.setOnKeyListener(新Dialog.OnKeyListener(){

            @覆盖
            公共布尔onKey(DialogInterface为arg0,INT关键code,
                    KeyEvent的事件){
                // TODO自动生成方法存根
                如果(键code == KeyEvent.KEY code_BACK){
                    完();
                    dialog.dismiss();
                }
                返回true;
            }
        });
 

I am developing one application. In that when the button is pressed i will open a dialog,With OK and Cancel buttons.

It works fine.

My problem is before open the dialog when user press back button i am handling like as fallows

public boolean onKeyDown(int keyCode, KeyEvent event) 
{
    if ((keyCode == KeyEvent.KEYCODE_BACK)) 
    {

    }
 return super.onKeyDown(keyCode, event);
}

It works fine.But when user open the dialog and press the back button,the above method is not called.

How can i handle this?

If any one know the solution please help me

Thanks in advance

解决方案

dialog.setOnKeyListener(new Dialog.OnKeyListener() {

            @Override
            public boolean onKey(DialogInterface arg0, int keyCode,
                    KeyEvent event) {
                // TODO Auto-generated method stub
                if (keyCode == KeyEvent.KEYCODE_BACK) {
                    finish();
                    dialog.dismiss();
                }
                return true;
            }
        });

这篇关于如何处理后退按钮,在对话框中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆