Asynchronous Html.ImageGetter for setting multiple images in a TextView

Posted by thedude19 on Stack Overflow See other posts from Stack Overflow or by thedude19
Published on 2011-02-03T15:14:12Z Indexed on 2011/02/03 15:25 UTC
Read the original article Hit count: 783

Filed under:
|
|
|

I'm writing an application that takes HTML pages and parses them to display on the screen. Specifically, this application pulls HTML from a message board and lists posts made by users.

The problem is that a lot of the content in posts are pictures in <img> tags, so I need to write a Html.ImageGetter to handle the downloading of the images.

My textView.setText() method will look like this:

myTextView.setText(Html.fromHtml(myText, new ImageGetter() {                 
        @Override
        public Drawable getDrawable(String source) {
        Drawable d;

        // Need to async download image here 

         return d;
        }
    }, null));

Doing this synchronously is trivial, but is there a suggested way to do this asynchronously so that it doesn't lock up my UI thread? I would also like to eventually build in caching of these images, but I imagine that would be pretty simple once the async downloading was there.

© Stack Overflow or respective owner

Related posts about java

Related posts about android