当我单击搜索按钮时,防止 ProgressDialog 被关闭(Android) [英] Prevent ProgressDialog from being dismissed when I click the search button (Android)

查看:25
本文介绍了当我单击搜索按钮时,防止 ProgressDialog 被关闭(Android)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在长时间运行的操作中,我显示了一个弹出对话框(从 ProgressDialog 创建以防止发生其他操作).

In a long-running operation, I'm showing a popup dialog (created from ProgressDialog to prevent other operations from happening).

我已使用 setCancelable(false) 使其不可取消,因此我无法使用后退按钮将其关闭,但令人惊讶的是,搜索硬件按钮会关闭对话框!

I have made it non-cancellable with setCancelable(false), so I can't close it using the back button, but surprisingly, the Search hardware button dismisses the dialog!

更准确地说,显示了全局搜索应用程序,当我回到我的应用程序时,对话框已被关闭.

More exactly, the global search application is displayed, and when I come back to my app, the dialog has been dismissed.

知道如何防止对话框被关闭吗?

Any idea how to prevent the dialog from being dismissed?

推荐答案

这行得通(注意我把它放在对话框生成器上):

This works (notice I put it on the dialog builder):

.setOnKeyListener(new DialogInterface.OnKeyListener() {

    @Override
    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_SEARCH && event.getRepeatCount() == 0) {
            return true; // Pretend we processed it
        }
        return false; // Any other keys are still processed as normal
    }
})

也许甚至可以抓住正负按钮按下,处理这些,对任何其他键返回 true.如果你能弄清楚那会很好奇......

Maybe it's even possible to grab the positive and negative button presses, and only handle these, return true for any other keys. Would be curious if you can figure that out...

PS:我在某处读到对话框中有更多漏洞",即您无需点击任何按钮即可摆脱它.这显然是一个.有人知道其他人吗?

PS: I read somewhere there are more "holes" in the dialog, i.e you can get rid of it without hitting any buttons on it. This was apparently one. Does anybody know of any others?

这篇关于当我单击搜索按钮时,防止 ProgressDialog 被关闭(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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