我一直在评估
NOSTRA的
Universal-Image-Loader库以异步下载图像并在ListView中显示它们.到目前为止,除了一个问题之外,它的工作正常
有时,当列表被滚动时,内存缓存中的位图会附加到错误的ImageView中.滚动停止后,将附加正确的图像.这种情况是相当罕见的,我找不到100%的方式来复制它.我最后一次发生了video.
这是ArticleAdapter代码,可以在那里找到UIL配置和bindView()方法.
public class ArticleAdapter extends CursorAdapter { private LayoutInflater inflater; private ViewHolder holder; public ArticleAdapter(Context context,Cursor cursor,boolean autoRequery) { super(context,cursor,autoRequery); imageLoader = ImageLoader.getInstance(); DisplayImageOptions options = new DisplayImageOptions.Builder() .showStubImage(R.drawable.download_progress_thumb) .cacheInMemory() .cacheOnDisc() .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) .build(); ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(context) .threadPriority(Thread.NORM_PRIORITY - 2) .threadPoolSize(4) .discCache(new UnlimitedDiscCache(Utils.getCacheDirectory(context))) .defaultDisplayImageOptions(options) .build(); imageLoader.init(configuration); titleIndex = cursor.getColumnIndex(Articles.TITLE); descriptionIndex = cursor.getColumnIndex(Articles.DESCRIPTION); isUnreadIndex = cursor.getColumnIndex(Articles.IS_UNREAD); isNewIndex = cursor.getColumnIndex(Articles.IS_NEW); urlIndex = cursor.getColumnIndex(Articles.URL); hostIndex = cursor.getColumnIndex(Articles.HOST); timeIndex = cursor.getColumnIndex(Articles.PUBLISH_TIME); bkgUnreadArticle = context.getResources().getColor(R.color.list_bkg_unread_article); bkgReadArticle = context.getResources().getColor(R.color.list_bkg_read_article); textUnreadTitle = context.getResources().getColor(R.color.list_text_unread_title); textReadTitle = context.getResources().getColor(R.color.list_text_read_title); inflater = LayoutInflater.from(context); } @Override public void bindView(View view,Context context,Cursor cursor) { String date = Utils.format(cursor.getLong(timeIndex),Utils.DATE); holder = (ViewHolder) view.getTag(); holder.titleView.setText(cursor.getString(titleIndex)); holder.descriptionView.setText(date); int isNew = cursor.getInt(isNewIndex); if (isNew == 1) holder.isNewView.setVisibility(View.VISIBLE); else holder.isNewView.setVisibility(View.INVISIBLE); int isUnread = cursor.getInt(isUnreadIndex); if (isUnread == 1){ holder.titleView.setTextColor(textUnreadTitle); holder.rowLayout.setBackgroundColor(bkgUnreadArticle); } else { holder.titleView.setTextColor(textReadTitle); holder.rowLayout.setBackgroundColor(bkgReadArticle); } String url = cursor.getString(urlIndex); String host = cursor.getString(hostIndex); if (host.equalsIgnoreCase(Consts.HOST_LENTA) || host.equalsIgnoreCase(Consts.HOST_REALTY)) { holder.thumbView.setVisibility(View.VISIBLE); imageLoader.displayImage(Utils.makeImageUrl(url,Utils.THUMBNAIL),holder.thumbView); } else holder.thumbView.setVisibility(View.GONE); } @Override public View newView(Context context,ViewGroup parent) { View v = inflater.inflate(R.layout.articlelist_item,null); ViewHolder holder = new ViewHolder(); holder.titleView = (TextView) v.findViewById(R.id.list_title); holder.descriptionView = (TextView) v.findViewById(R.id.list_description); holder.thumbView = (ImageView) v.findViewById(R.id.list_thumb); holder.isNewView = (TextView) v.findViewById(R.id.list_read_unread); holder.rowLayout = (LinearLayout) v.findViewById(R.id.list_row); v.setTag(holder); return v; } }
我真的很感谢任何关于这件事的帮助.