如何检测从网络加载图片-进度条
How to detect the loading of the image from the Internet - progress bar
我有一个class:
public class DownloadImageFromInternet extends AsyncTask<String, Void, Bitmap> {
private ImageView imageView;
public DownloadImageFromInternet(ImageView imageView) {
this.imageView = imageView;
}
protected Bitmap doInBackground(String... urls) {
String imageURL = urls[0];
Bitmap bimage = null;
try {
InputStream in = new java.net.URL(imageURL).openStream();
bimage = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error Message", e.getMessage());
e.printStackTrace();
}
return bimage;
}
protected void onPostExecute(Bitmap result) {
imageView.setImageBitmap(result);
}
}
我想创建一个进度条来检测我从 Internet 下载的图像的加载情况。
怎么做?
这是如何完成的:
public class DownloadImageFromInternet extends AsyncTask<String, Void, Bitmap> {
private ImageView imageView;
private ProgressDialog pd;
public DownloadImageFromInternet(ImageView imageView) {
this.imageView = imageView;
}
protected void onPreExecute() {
pd = new ProgressDialog(); //Create dialog
pd.show(); // show dialog
}
protected Bitmap doInBackground(String... urls) {
...
..
return bimage;
}
protected void onPostExecute(Bitmap result) {
pd.dismiss();
...
}
}
我有一个class:
public class DownloadImageFromInternet extends AsyncTask<String, Void, Bitmap> {
private ImageView imageView;
public DownloadImageFromInternet(ImageView imageView) {
this.imageView = imageView;
}
protected Bitmap doInBackground(String... urls) {
String imageURL = urls[0];
Bitmap bimage = null;
try {
InputStream in = new java.net.URL(imageURL).openStream();
bimage = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error Message", e.getMessage());
e.printStackTrace();
}
return bimage;
}
protected void onPostExecute(Bitmap result) {
imageView.setImageBitmap(result);
}
}
我想创建一个进度条来检测我从 Internet 下载的图像的加载情况。 怎么做?
这是如何完成的:
public class DownloadImageFromInternet extends AsyncTask<String, Void, Bitmap> {
private ImageView imageView;
private ProgressDialog pd;
public DownloadImageFromInternet(ImageView imageView) {
this.imageView = imageView;
}
protected void onPreExecute() {
pd = new ProgressDialog(); //Create dialog
pd.show(); // show dialog
}
protected Bitmap doInBackground(String... urls) {
...
..
return bimage;
}
protected void onPostExecute(Bitmap result) {
pd.dismiss();
...
}
}