【问题标题】:Android:problem in displaying the progressbar dialog?Android:显示进度条对话框的问题?
【发布时间】:2011-02-27 01:08:35
【问题描述】:

在我的应用程序中,我尝试在函数完成执行后显示进度条并在函数完成执行后将其关闭...

我的代码定义如下:

 protected Dialog onCreateDialog(int id) {
        switch (id) {
            case PROCESS: {
                ProgressDialog dialog = new ProgressDialog(this);
                dialog.setTitle("Indeterminate");
                dialog.setMessage("Please wait while loading...");
                dialog.setIndeterminate(true);
                dialog.setCancelable(true);
                return dialog;
            }
        }
        return null;
    }




showDialog(PROCESS);
doFunction();
dismissDialog(PROCESS);

由于某种原因,没有显示 processdialog...

有人可以在这里帮助我吗... 有没有其他方法可以做到...

谢谢:)

【问题讨论】:

    标签: java android eclipse dialog progress-bar


    【解决方案1】:

    由于你的函数需要一些时间来处理,所以使用异步任务

    new AsyncTask<Void, Void, Void>() {
    
            @Override
            protected void onPreExecute()
            {
                 pd = ProgressDialog.show(getApplicationContext(),"", "Sending Image ...", true);
                Log.d(TAG, "onPreExecute()");
            }
    
            @Override
            protected Void doInBackground(Void... params)
            {
                doFunction();
                return null;
            }
    
            @Override
            protected void onPostExecute(Void res)
            {
                Log.d(TAG, "onPostExecute()");
                pd.dismiss();
            }
        }.execute();
    

    第二次将其设置为不确定意味着您只会看到一个圆圈。

    您应该将progress style 设置为STYLE_HORIZONTAL

    【讨论】:

    • 我已经尝试过了,但我得到了一个错误,比如......'android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application'......你能帮帮我吗....
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多