Android的后退按钮和进度对话框对话框、进度、按钮、Android

由网友(习惯用你的名字去拒绝别人)分享简介:我有一个AsyncTask的,显示了progressDialog同时工作(它调用runOnUiThread从内部doInBackground显示进度对话框)。I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUi...

我有一个AsyncTask的,显示了progressDialog同时工作(它调用runOnUiThread从内部doInBackground显示进度对话框)。

I have an AsyncTask that shows a progressDialog whilst working (it calls runOnUiThread from within doInBackground to show the progress dialog).

虽然它的运行我想允许使用后退按钮的取消操作;其他人遇到过这个问题:BACK按钮不工作,而progressDialog运行。

Whilst its running I want to allow the use of the back button to cancel the operation; someone else has had this problem: BACK Button is not working ,while progressDialog is running.

有关什么都原因,我不能答复该线程,因此不必启动另一个? (另一天的另一个问题)

For what ever reason I can't reply to that thread, hence having to start another?! (Another question for another day)

我有同样的想法桑迪但这code不会被调用,而该progressDialog正显示出,这是为什么?我已经实现了它在我的主要活动类,请问progressDialog采取前景注意力从我的课暂时?

I had the same idea as Sandy but this code is never called whilst the progressDialog is showing, why is this? I have implemented it inside my main activity class, does the progressDialog take the foreground focus away from my class temporarily?

推荐答案

首先,你应该表现出从的对话框preExecute ,把它藏在 OnPostExecute ,和 ​​- 必要时 - 通过出版进度进行修改。 (见这里)

First, you should show your dialog from OnPreExecute, hide it in OnPostExecute, and - if necessary - modify it by publishing progress. (see here)

现在你的问题: ProgressDialog.show()可以采取 OnCancelListener 作为参数。您应该提供一个叫取消()上的进度对话框实例。

Now to your question: ProgressDialog.show() can take a OnCancelListener as an argument. You should provide one that calls cancel() on the progress dialog instance.

例如:

    @Override
    protected void onPreExecute(){
        _progressDialog = ProgressDialog.show(
                YourActivity.this,
                "Title",
                "Message",
                true,
                true,
                new DialogInterface.OnCancelListener(){
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        YourTask.this.cancel(true);
                        finish();
                    }
                }
        );
    }

其中, _progressDialog YourTask ProgressDialog 成员

阅读全文

相关推荐

最新文章