0

As a prototype, I'm trying to modify the android-imagedownloader demo from the Android Developers Blog to work with HTML image tags rather than hard-coded ImageViews. I've modified it by replacing ImageAdapter.getView() with the following:

public View getView(final int position, View view, final ViewGroup parent) {
   TextView textView = (TextView) view;
    if (textView == null) {
       textView = new TextView(parent.getContext());
       textView.setPadding(6, 6, 6, 6);
    }
    textView.setText(Html.fromHtml("<img src=\"" + URLS[position] + "\"/>", 
       new ImageGetter() {
       @Override public Drawable getDrawable(final String source) {
          ImageView imageView = new ImageView(parent.getContext());
          imageDownloader.download(source, imageView);
          return imageView.getDrawable();
       }
    }, null));

    return textView;
}

None of the images are appearing in the ListView though and no errors are reported in Logcat. Do TextViews unlike ImageViews need to be refreshed somehow once the images are downloaded?

The original getView() was:

public View getView(int position, View view, ViewGroup parent) {
    if (view == null) {
        view = new ImageView(parent.getContext());
        view.setPadding(6, 6, 6, 6);
    }

    imageDownloader.download(URLS[position], (ImageView) view);

    return view;
}
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246

1 Answers1

0

I'm going to abandon my original idea of using HTML TextView to render my images since I don't think it will be a problem to limit the layout to a single image per TextView. For those who still really want to do this, this answer should guide you to the right solution. You'd have to pass the TextView to the BitmapDownloaderTask and in onPostExecute call setText again but with the newly downloaded or "decached" image.

It might also be necessary to force an update of the row in the ListView per Romain Guy's guidance.

Community
  • 1
  • 1
Jeff Axelrod
  • 27,676
  • 31
  • 147
  • 246