Asynchronous Html.ImageGetter for setting multiple images in a TextView
- by thedude19
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.