2011-02-27 82 views
0

在我的应用我试图显示采取一个函数来完成它的执行,并关闭它一个时间进度的函数执行完成后...Android:显示进度条对话框时出现问题?

我的代码定义如下:

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 ...

能有人帮我在这里请.... 是否有任何其他的方式来做到这一点...

谢谢:)

回答

2

由于您的功能需要一定的时间来处理,使用异步任务

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 styleSTYLE_HORIZONTAL

+0

我都试过,但我得到像......“android.view.WindowManager $ BadTokenException错误:无法添加窗口 - 令牌null不是一个应用程序'....你能帮我出去的人.... – kAnNaN 2011-02-27 14:12:59