Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
510 views
in Technique[技术] by (71.8m points)

dialog - Prevent ProgressDialog from being dismissed when I click the search button (Android)

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

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?

question from:https://stackoverflow.com/questions/2502443/prevent-progressdialog-from-being-dismissed-when-i-click-the-search-button-andr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
    }
})

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: 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...