您好,我使用加载图像来加载图像。但是我的图像没有加载。我为此工作并开发了一个演示程序,如下所示。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
new DownloadImageTask((ImageView) findViewById(R.id.my_image))
.execute("http://www.morroccomethod.com/components/com_virtuemart/shop_image/category/resized/Raw_Conditioner_500835f701532_175x175.jpg");
}
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView bmImage;
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd = new ProgressDialog(ImageLoadExampleActivity.this);
pd.show();
}
public DownloadImageTask(ImageView bmImage) {
this.bmImage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
bmImage.setImageBitmap(result);
pd.dismiss();
}
}
这没用。但是,如果我当时更改了图像的 URL,图像就会成功加载。我的问题是这个特定的 url 没有加载到我的 android 应用程序中。请帮我找到这个。我花了一天时间。提前致谢。
-哈迪克