我有一个listview,每行有一个textview和一个按钮。按钮背景使用某些条件设置。如果我在列表中有行数并滚动,则按钮背景会变得混乱。这意味着滚动错误的背景设置为按钮背景。我该如何解决这个问题?我的适配器类如下所示:
public View getView(int position, View convertView, ViewGroup parent) {
final PhotoCondtionthreeItemView item;
Photo place = (Photo) getItem(position);
if (convertView != null) {
item = (PhotoCondtionthreeItemView) convertView;
} else {
item = new PhotoCondtionthreeItemView(context, place,
membershipSign);
}
item.setShareTag(place.getLink()+"@@@"+place.getServerPhotoId());
item.setBaseLayoutTag(place.getLink() + "@@@"
+ place.getServerPhotoId() + "@@@" + place.getIsGallery()
+ "@@@" + place.getId());
File file;
try {
file = new File(place.getLink());
if (file.exists()) {
if (cache.containsKey(place.getLink())) {
item.setThumbImg(cache.get(place.getLink()));
} else {
Bitmap bitmap = BitmapResizer.decodeFile(file, 50, 50);
item.setThumbImg(bitmap);
cache.put(place.getLink(), bitmap);
}
} else {
item.setThumbImgMissing();
}
} catch (Exception e) {
Log.e("PhotoCondThree ERROR", e.toString());
}
return item;
}
在PhotoCondtionthreeItemView类中创建了列的行。 (未使用xml作为列表行)。
任何人都可以帮助我吗?
谢谢
答案 0 :(得分:1)
这听起来像是由ListView重复使用布局元素引起的问题。如果没有看到实际将图像设置为视图的代码,那么肯定有点难以说明,但是这篇博文可能会有所帮助......
http://android-developers.blogspot.com/2009/05/drawable-mutations.html
答案 1 :(得分:1)
在数据更改时调用yourListViewadapter.notifyDataSetChanged()