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;
}