0

下面是我的 CursorAdapter 的 bindView() 代码。

整个中间部分是我在其中一个图像上设置一个标识符,这将防止我的 ImageLoader(一个惰性图像加载器)将该数据重新绑定到已经与正确数据绑定的视图。

如果该行的数据保持不变,我有点期望 ListView 在 notifyDataChanged() 之后的行上不请求 bindView。

考虑到这个问题,我猜我的适配器必须提供一种在跳过之前确定数据相等性的方法,但是查看它的源代码 getItem 和 getItemId 并没有用于此目的。

我是在做一些不必要的hacky,还是这是一个常见的优化?

   @Override
    public void bindView(View view, Context context, Cursor cursor) {
        int position = cursor.getPosition();

        ImageView thumbnailIv = (ImageView) view.getTag(R.id.thumbnail);

        //Do i really need this to avoid unnecessarily rebinding data to this view??
        Integer cellPosition = (Integer)thumbnailIv.getTag();
        if(cellPosition != null && position == cellPosition.intValue()){
            //skip!
            return;
        }

        thumbnailIv.setTag(Integer.valueOf(position));

        Post post = new Post(cursor); //get the data out of the row.

        ImageLoader.getInstance().displayImage(post.getThumbnailUrl(), thumbnailIv);
    }
4

0 回答 0