0

i m loading images from rss description using

String description2 = des.get(position).toString();

       Spanned description = Html.fromHtml(description2, new ImageGetter() {
            @Override
         public Drawable getDrawable(String source) {                  
            Drawable d = null;
            try {
                        InputStream src = imageFetch(source);
                        d = Drawable.createFromStream(src, "src");
                        if(d != null){
        d.setBounds(0,0,d.getIntrinsicWidth(),
        d.getIntrinsicHeight());
                        }
        } catch (MalformedURLException e) {
                  e.printStackTrace(); 
            } catch (IOException e) {
                  e.printStackTrace();  
            }

        return d;
        }

            public InputStream imageFetch(String source)
                    throws MalformedURLException,IOException {
        URL url = new URL(source);
        Object o = url.getContent();
        InputStream content = (InputStream)o;
        // add delay here (see comment at the end)     
        return content;
        }

        },null);

How can i put them into an AsyncTask,in order to get a progress bar until the images download? Thanks!

pad
  • 41,040
  • 7
  • 92
  • 166
menu_on_top
  • 2,613
  • 14
  • 44
  • 71
  • Look at [Android HTML ImageGetter as AsyncTask](http://stackoverflow.com/questions/7424512/android-html-imagegetter-as-asynctask) – user370305 Dec 24 '11 at 14:34

2 Answers2

0

You can take a look at this tutorial, which downloads images from the web and uses progress bar. All done in AsyncTask and the complete source is available.

hovanessyan
  • 30,580
  • 6
  • 55
  • 83
0

you can use this WebImageView from generic-store-for-android

which is adapted from droid-fu project.

here is an example usage;
-> define inside your layout

<com.wareninja.opensource.droidfu.widgets.WebImageView
  android:id="@+id/img_fbProfilePic"
  android:visibility="visible"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
/>


-> set the url to load

WebImageView fbProfilePic = (WebImageView) this.findViewById(R.id.img_fbProfilePic);
fbProfilePic.setImageUrl("http://graph.facebook.com/100001789213579/picture");
fbProfilePic.loadImage();
Yilmaz Guleryuz
  • 9,313
  • 3
  • 32
  • 43