Prevent ProgressDialog from being dismissed when I click the search button (Android)(当我单击搜索按钮时,防止 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当我单击搜索按钮时,防止 ProgressDialog 被关闭(Android)
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
