【发布时间】:2011-02-10 12:48:30
【问题描述】:
我有一个包含几个列表视图的应用程序。 listviews 包含由 imageviews 和 textviews 组成的项目。
所有图像在服务器上都是缩略图大小,用于加载它们的模式如下:
- 实例化 DrawableManager
- 在 getView 方法中,我执行以下操作 1 ) 将 thumb uri 和 ImageView 实例传递给 drawablemanagers getImageAsync 方法 1.2 ) 如果图像存在,该方法将首先查看 sd 卡,如果从 SD 卡加载它并保存软引用 + 更新 imageview 可绘制 1.2 ) 如果 sd 上不存在。从 HTTP 获取并保存在 SD(如果有足够的空间)作为软引用并更新 imageview drawable。
当图像存在于 sd 卡上时,一切正常。但第一次(或使用没有 sd 卡的应用程序时)图像似乎在滚动时填充到错误的列表视图行中。当我停止滚动时,问题会在几秒钟后自行修复。
这几乎就像 ImageView 引用是池化的一样。
有什么想法吗?
我还包括 getView 方法:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder vh;
if (convertView == null) {
convertView = inflater.inflate(R.layout.informationrow, null);
vh = new ViewHolder();
vh.imageView = (ImageView) convertView.findViewById(R.id.rowInformationIcon);
vh.textView = (TextView) convertView.findViewById(R.id.rowInformationTitleLine);
convertView.setTag(vh);
}
else
{
vh = (ViewHolder) convertView.getTag();
}
CustomCategory cc = items.get(position);
if (cc != null) {
vh.textView.setText(cc.get_name());
if (cc.getMediaUrl() != null) {
_drawMgr.fetchDrawableOnThread(cc.getMediaUrl(), vh.imageView);
vh.imageView.setBackgroundDrawable(getResources().getDrawable(R.drawable.imageframe));
}
else {
vh.imageView.setImageDrawable(getResources().getDrawable(R.drawable.trans4040));
vh.imageView.setBackgroundDrawable(null);
}
}
return convertView;
}
谢谢!
【问题讨论】:
标签: java android asynchronous imageview listactivity