我为Item的listView(myRSSTitleListAdapter)扩展ArrayAdapter创建了自己的适配器(Item是my实体类)。我这样重写了getView方法:
public View getView(int position, View converView, ViewGroup parent) {
View view = converView;
if(view == null) {
LayoutInflater li =(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(layout, null);
}
final Item listItem = items[position];
if(listItem != null) {
ImageView image = (ImageView)view.findViewById(R.id.image);
image.setImageBitmap(ImageTool.loadImage(listItem.getImageURL()));
HTMLUtilities htmlTool = HTMLUtilities.getInstance();
TextView title = (TextView)view.findViewById(R.id.label);
title.setText(htmlTool.escapeHTML(listItem.getTitle()));
}
return view;
}
ImageTool是我编写的一个类,loadImage
从传递给它的url返回一个位图。我在我的ListActivity中这样调用ListActivity:
setListAdapter(new myRSSTitleListAdapter(this, R.layout.rss_items, items));
项是项的数组。
rss_items
是带有imageView和textView的线性布局。
对于textView,一切都很好,setText对我返回的视图有影响,但是图像没有出现(我确信位图就在这里)
谢谢
发布于 2011-04-03 09:23:08
我认为问题在loadImage
中,因为您的代码看起来不错。
应该发生两件事中的一件:
loadImage
工作正常,那么您的行中的文本应该需要很长时间才会出现,因为getView
在loadImage
运行之前不会返回。loadImage
有错误或正在异步工作,那么getView
将立即返回,并且只设置文本,这是您描述的行为。异步地将映像加载到ImageView
中要比应该加载的图像复杂得多。如果你不能让DroidFu的WebImageView开始工作,你可以试试它。
https://stackoverflow.com/questions/5531095
复制相似问题