我有一个ArrayAdapter,它的getView方法有:
public View getView(int position, View convertView, ViewGroup parent) {
//get object against selected list item
book thisbook = getItem( position );
ViewHolder viewHolder; // view lookup cache stored in tag
if (convertView == null) {
viewHolder = new ViewHolder();
LayoutInflater inflater = LayoutInflater.from(getContext());
convertView = inflater.inflate( R.layout.book, parent, false);
viewHolder.bookImage = (ImageView) convertView.findViewById(R.id.bookImage);
viewHolder.txtbookTitle = (TextView) convertView.findViewById(R.id.txtbookTitle);
//download image and set the bitmap for bookImage ImageView
new DownloadImageService( viewHolder.bookImage ).execute( thisbook.getImageUrl() );
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
viewHolder.txtbookTitle.setText(thisbook.getbookTitle());
viewHolder.bookImage = thisbook.getbookImage();
viewHolder.txtbookId.setText(thisbook.getbookId());
new DownloadImageService( viewHolder.bookImage ).execute( thisbook.getImageUrl() );
return convertView;
}
现在,当我向下滚动时,我将更多项目加载到我的数据ArrayList中,然后调用myAdapter.notifyDataSetChanged(),然后发生的事情是书籍图像混乱,即新加载的项目将具有来自另一个项目的图像,即已加载到列表中。例如如果已经在列表中加载了id为1的图书,并且当向下滚动列表视图并且加载一本新书时,图像为a.jpeg,则说明其ID为10.JPEG,但它的a.jpeg为blww另一本书,它奇怪,不确定我做错了什么。
在调试时我检查了输入ArrayList的适配器,我可以完全看到ArrayList中的所有书籍。