如何下载ListView控件的HTML图像异步? [英] How can I download ListView HTML images asynchronously?

查看:185
本文介绍了如何下载ListView控件的HTML图像异步?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为原型,我试图修改href="http://$c$c.google.com/p/android-imagedownloader/" rel="nofollow"> Android的imagedownloader演示<的 Android开发者博客一起工作HTML图像标记,而不是硬codeD ImageViews 。我已经通过替换修改了它 ImageAdapter.getView()为以下内容:

 公开查看getView(最终诠释的立场,观点来看,最终的ViewGroup父){
   TextView中的TextView =(TextView的)观点;
    如果(TextView的== NULL){
       TextView的=新的TextView(parent.getContext());
       textView.setPadding(6,6,6,6);
    }
    textView.setText(Html.fromHtml(&LT; IMG SRC = \+ URLS [位置] +\/&gt;中,
       新ImageGetter(){
       @覆盖公共绘制对象getDrawable(最后弦乐源){
          ImageView的ImageView的=新ImageView的(parent.getContext());
          imageDownloader.download(来源ImageView的);
          返回imageView.getDrawable();
       }
    }, 空值));

    返回的TextView;
}
 

无图像都出现在ListView,但并没有错​​误报告在logcat中。做 TextViews ImageViews 需要以某种方式刷新一次的图像下载?

getView()是:

 公开查看getView(INT的立场,观点来看,一个ViewGroup父){
    如果(查看== NULL){
        鉴于=新ImageView的(parent.getContext());
        view.setPadding(6,6,6,6);
    }

    imageDownloader.download(URLS [位置],(ImageView的)观点);

    返回查看;
}
 

解决方案

我要放弃我原来使用的HTML 的TextView 的想法,使我的图片,因为我不'T认为这将是一个问题的布局限制每的TextView 一个单一的形象。对于那些谁还真想这样做,这个答案应该引导您正确的解决方案。你必须要通过的TextView BitmapDownloaderTask onPostExecute 呼叫的setText 再次但是随着新下载或decached的形象。

这可能还需要强制在的ListView 元的罗曼盖伊的指导

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

解决方案

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.

这篇关于如何下载ListView控件的HTML图像异步?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆