-2

I have image url in string as

String imgurl=days.getString("icon_url");

getting this url jsonarray which is saved in shared preference how to show this string image url into ImageView?

Any help???

Neo
  • 1,469
  • 3
  • 23
  • 40
Zaib Niaz
  • 11
  • 5
  • @Zaib Niaz, If you just want to show Image in ImageView fro URL. You need this https://github.com/nostra13/Android-Universal-Image-Loader OR https://github.com/square/picasso – QAMAR Nov 17 '15 at 07:12
  • url is in for loop and url has to change after every loop?? any suggestion? – Zaib Niaz Nov 17 '15 at 07:13

1 Answers1

0

You can either use UniversalImageLoader or picasso Library to load image in imageview from url.

Add internet permission in your AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

And to download image using AsyncTask use following code:

private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
    ImageView bmImage;

    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);
    } 
} 

And to use above code to load image from url in imageview use following code:

new DownloadImageTask(mImageView).execute(imgurl); 
Anjali
  • 1
  • 1
  • 13
  • 20