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

前端 未结 3 1066
孤独总比滥情好
孤独总比滥情好 2020-12-25 09:25

I want to set a TextView with SpannableString which is from the method below:

Html.fromHtml(String source, Html.ImageGetter imageGe         


        
3条回答
  •  误落风尘
    2020-12-25 09:43

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

    Spanned spannedContent = Html.fromHtml(htmlString, new ImageGetter() {
    
            @Override
            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?

提交回复
热议问题