【问题标题】:Progressbar does not show up. Why?进度条不显示。为什么?
【发布时间】:2010-06-28 21:26:39
【问题描述】:

当我按下按钮时,我希望显示一个进度条,因此我插入了以下代码:

progDailog = ProgressDialog.show(this, "正在下载数据", "请稍候....", true);

但是progressDialog 根本没有显示。为什么?我还需要做些什么来展示它?

/M

【问题讨论】:

    标签: android progressdialog


    【解决方案1】:

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

    我会选择来自Android APIAsyncTask

    以下是调用 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。

    【讨论】:

    • 谢谢 抱歉这么晚才回来
    • 没问题。如果我确实回答了这个问题,请标记它,以便其他发现您的问题的人知道这有帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-13
    相关资源
    最近更新 更多