[英]ProgressDialog does not update in ActionBarSherlock
我無法在進度對話框中看到任何進度更新。
在活動類中:
void retrieveImages()
{
mImageUriList = new ArrayList<String>();
mImageUriList = Utils.fetchImages(this);
mProgressDialog = new ProgressDialog(this);
// progress dialog here is class level activity member
mProgressDialog.show();
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMessage("Processing Images..");
mProgressDialog.setMax(100);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCanceledOnTouchOutside(false);
new GetImageAsyncTask(this, mImageUriList,mProgressDialog).execute();
// passing progress dialog to async task
}
在異步任務中
@Override
protected Void doInBackground(Void... params)
{
int progress_status;
float count=imageUriList.size();
float increment=0;
float p=(increment/count)*100;
for(int i=0;i<count;i++)
{
increment++;
//do some operation
p=(increment/count)*100;
progress_status=Math.round(p);
publishProgress(progress_status);
Log.i(TAG, "progress value-"+progress_status);
}
return null;
}
@Override
protected void onProgressUpdate(Integer... values)
{
//super.onProgressUpdate(values);
progressDialog.setProgress(values[0]);
}
我只能看到微調器和消息“正在處理圖像..”,我沒有看到任何進度條/更新
我正在使用 ActionBarSherLock,我也在這里嘗試了這個似乎也不起作用的解決方案,它也只是在操作欄上顯示進度微調器。 我想要一個對話框來顯示進度,而不是在操作欄上。
這里的技巧不是在 Activity 中創建進度條,而是通過將 Activity 的上下文傳遞到 AsyncTask 中來在 AsyncTask 中創建進度對話框,看看這里的代碼
void retrieveImages()
{
//some method in sherlock activity
mImageUriList = new ArrayList<String>();
mImageUriList = Utils.fetchImages(this);
new GetImageAsyncTask(this, mImageUriList).execute();
//NOT passing progress dialog to async task,just activity context
}
在異步任務中
在構造函數中
GetImageAsyncTask(Context mContext,ArrayList<String> mImageUriList)
{
// Other intializations
mProgressDialog = new ProgressDialog(mContext);
mProgressDialog = new ProgressDialog(this);
// progress dialog here is asynctask class member
mProgressDialog.setIndeterminate(false);
mProgressDialog.setMessage("Processing Images..");
mProgressDialog.setMax(100);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCanceledOnTouchOutside(false);
}
現在 onPreExecute(),顯示/加載進度對話框
public void onPreExecute()
{
//show dialog box on pre execute
mProgressDialog.show();
}
保持doInBackground
和onProgressUpdate
相同
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.