Android how to display Image from URL in fragment
<p>ImageView (image from URL) cannot display in Fragment (means blank screen).</p>

<pre><code>ImageView newsimage = (ImageView) findViewById(R.id.newsimg);
ImageLoad downloader = new ImageLoad(newsimage);
downloader.execute("http://www.mysite.com/pp.jpg");
</code></pre>

<p>It's correct to display in Activity page but when I change to Fragement, it cannot display at all. Please let me know anything is wrong.</p>

<pre><code>import java.io.IOException;
import java.lang.ref.WeakReference;
import java.net.MalformedURLException;
import java.net.URL;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.widget.ImageView;

public class ImageLoad extends AsyncTask&lt;String, Void, Bitmap&gt; {

    private String url;
    private final WeakReference&lt;ImageView&gt; imageViewReference;

    public ImageLoad(ImageView imageView) {
        imageViewReference = new WeakReference&lt;ImageView&gt;(imageView);
    }

    protected Bitmap doInBackground(String... params) {
        url = params[0];
        try {
            return BitmapFactory.decodeStream(new URL(url).openConnection()
                    .getInputStream());
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }

    protected void onPostExecute(Bitmap result) {
        if (imageViewReference != null) {
            ImageView imageView = imageViewReference.get();
            if (imageView != null) {
                imageView.setImageBitmap(result);
            }
        }
    }

    protected void onPreExecute() {
        if (imageViewReference != null) {
            ImageView imageView = imageViewReference.get();
            if (imageView != null) {
                imageView.setImageResource(R.drawable.no_image);
            }
        }
    }
}
</code></pre>
