作为原型,我正在尝试修改Android 开发者博客中的android-imagedownloader 演示,以使用 HTML 图像标签而不是硬编码的. 我已通过替换为以下内容对其进行了修改:ImageViews
ImageAdapter.getView()
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;
}
但是,ListView 中没有出现任何图像,Logcat 中也没有报告错误。TextViews
下载图像后是否ImageViews
需要以某种方式刷新?
原来getView()
是:
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;
}