1

嗨,我看过类似的问题,但我无法解决问题。它不工作。我正在尝试从服务器下载一些图像并将它们放在 android 应用程序的 ImageViews 中。

public class MyAsyncTask extends AsyncTask {
  protected String doInBackground(String... params)  {
    ...........
    URL urlImagine = new URL("http://s.ytimg.com/yts/img/favicon-vfldLzJxy.ico");
    //Version 1:
    URLConnection conn = urlImagine.openConnection();
    inputStreamImagine = (InputStream)conn.getContent();
    ..........
    //version 2:
    inputStreamImagine = urlImagine.openStream();
    bufImagine = new BufferedInputStream(inputStreamImagine);
    .........
  }
}
    //Some other class:
    .............. 
    //http://stackoverflow.com/questions/15569953/download-image-from-image-url-to-image-view
    //version 1:
    //Download Image From Image URL to image view
    if (inputStreamImagine!=null){
      Bitmap bitmap = BitmapFactory.decodeStream(inputStreamImagine);      
      imageView.setImageBitmap(bitmap);
    }
    //version 2:
    if (bufImagine!=null){
      // Convert the BufferedInputStream to a Bitmap
      Bitmap bMap = BitmapFactory.decodeStream(bufImagine);
      Drawable drawable = new BitmapDrawable(bMap);
      imageView.setBackgroundDrawable(drawable);
      //iv.setImageDrawable(drawable);      
   }

我已经尝试使用这两个示例,但 ImageView 没有加载任何图像。请你帮助我好吗?

4

1 回答 1

1

您应该使用延迟加载概念。您应该查看以下链接:

ListView 中图像的延迟加载

于 2013-11-01T12:01:35.127 回答