0

When I press a button I would like to have a progressbar showing up so I inserted this code:

progDailog = ProgressDialog.show(this, "Downloading data", "please wait....", true);

But the progressDialog is not showing at all. Why? What more do I need to do to show it?

/M

4

1 回答 1

3

如果您希望在执行某些工作时显示进度条,则需要为该任务使用另一个线程,这样它就不会阻塞 UI。这就是这个问题的“为什么”;进度对话框被数据下载阻止,因此无法显示。

我会使用Android API中的AsyncTask

以下是调用Activity中的子类:

private class myTask extends AsyncTask<Void, Void, Void> {
    private ProgressDialog progDialog;

    onPreExecute() {
        progDailog = ProgressDialog.show(this, "Downloading data", "please wait....", true);
    }

    doInBackground(Void... params) {
        // Here's where the work should happen
    }

    onPostExecute(Void result) {
        // Close the dialog, pass results back, whatever...
    }
}

请原谅任何代码错误 - 我无法访问 SDK。

于 2010-06-28T13:04:38.757 回答