动态更新图片来自URL与Android

问题描述:

所以我有这个计划,抓住RSS提要的http://www.muttville.org/mutts/feed和显示可用狗的名单,基本上填写每个项目在ListView与左边的狗的图像,并关于右边的狗的标题。动态更新图片来自URL与Android

我的应用程序执行,并争夺,解析XML提要罚款。 onCreate,它将图像URL作为字符串存储在每个项目中。我有一个RSSFeed数据结构,它基本上是一个RSSItem对象数组。问题是搞清楚如何异步更新图像。

我有我实际上是从在谷歌Android开发人员博客,更新图片,并存储了一个imageDownloader,但预紧很长。我宁愿立即开始显示这些项目,并更新图像,因为我得到它们。烦人,列表视图滚动真的unresponsively起初为好,叫我imageDownloader再次检索的项目。有没有一些方法,我可以让ImageViews随便抓一个指针的ImageView对象RSSItem中,然后只更新了吗?

我很新的Android开发,所以有一个很好的机会,我不知道一些基本的东西。这里是我的适配器代码:

私有类FeedItemAdapter扩展ArrayAdapter {

private List<RSSItem> items; 

    public FeedItemAdapter(Context context, int textViewResourceId, List<RSSItem> items) { 
     super(context, textViewResourceId, items); 
      this.items = items; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
      View v = convertView; 
      if (v == null) { 
       LayoutInflater vi = 
        (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       v = vi.inflate(R.layout.displayitem, null); 
      } 

      RSSItem o = items.get(position); 
      if (o != null) { 
        ImageView tt = (ImageView) v.findViewById(R.id.leftimage); 
        TextView bt = (TextView) v.findViewById(R.id.righttext); 
        if (tt != null) { 
         //get image from url string 
         imageDownloader.download(o.getImageString(), tt); 
        } 
        if(bt != null){ 
          bt.setText(feed.getItem(position).getTitle()); 
        } 
      } 
      return v; 
    } 


} 

创建一个继承ImageView的一个新的类,默认显示一个“悬而未决”的形象,并有开始从网络加载的功能另一个线程。完成后,更新图像。