shiami shiami - 1 month ago 11x
Android Question

Display images on Android using TextView and Html.ImageGetter asynchronously?

I want to set a

which is from the method below:

Html.fromHtml(String source, Html.ImageGetter imageGetter,
Html.TagHandler tagHandler)

But the
here need to override the method below:

public abstract Drawable getDrawable(String source)

Because I need to get the drawable from the internet, I have to do it asynchronously and seems it is not.

How to make it work?


Now I'm using an AsyncTask to download the images in the ImageGetter:

Spanned spannedContent = Html.fromHtml(htmlString, new ImageGetter() {

        public Drawable getDrawable(String source) {
            new ImageDownloadAsyncTask().execute(textView, htmlString, source);
            return null;
    }, null);

And set the text again into the TextView when the image has been downloaded.

Now it works. But It failed when I tried to do the TextView.postInvalidate() to redraw the downloaded images. I have to do setText() again in the AsyncTask.

Does anyone know why?