实现进度对话框,其中要下载的图像数量超过 1
我想在从服务器下载图像时显示进度对话框。我能够下载图像并实现进度对话框,但我的问题是进度对话框不会被关闭,它只显示最后下载的图像。
我正在使用以下代码:
public class BackgroundAsyncTask extends AsyncTask<String, Integer, Bitmap> {
int myProgress;
@Override
protected void onPostExecute(Bitmap result) {
image.setVisibility(View.VISIBLE);
image.setImageBitmap(result);
if(dialog.isShowing())
{
dialog.dismiss();
}
return;
}
protected void onPreExecute() {
dialog = ProgressDialog.show(ProfilePageNormalUser.this,
"Loading...", "Please wait...");
}
@Override
protected Bitmap doInBackground(String... paths) {
return DownloadFile(imageUrl);
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
progressBar.setProgress(values[0]);
}
}
以及以下代码来调用这些:
new BackgroundAsyncTask().execute(imageUrl);
任何人都可以告诉我可能是什么问题吗 谢谢
I want to show progress dialog at the time images are being downloaded from server. i am able to download the images and implement the progress dialog but my problem is that the progress dialog doesnot get dismissed and it only shows the last downloaded image.
I am using the following code for that :
public class BackgroundAsyncTask extends AsyncTask<String, Integer, Bitmap> {
int myProgress;
@Override
protected void onPostExecute(Bitmap result) {
image.setVisibility(View.VISIBLE);
image.setImageBitmap(result);
if(dialog.isShowing())
{
dialog.dismiss();
}
return;
}
protected void onPreExecute() {
dialog = ProgressDialog.show(ProfilePageNormalUser.this,
"Loading...", "Please wait...");
}
@Override
protected Bitmap doInBackground(String... paths) {
return DownloadFile(imageUrl);
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
progressBar.setProgress(values[0]);
}
}
and the following for calling these:
new BackgroundAsyncTask().execute(imageUrl);
Can anyone tall me what could be the problem
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须调用 publishProgress() 在每张图像之后。然后,
publishProgress()
将在 UI 线程上调用onProgressUpdate()
。You have to call publishProgress() after each image.
publishProgress()
will then callonProgressUpdate()
on the UI thread.