Android listview duplicates scroll item

I have a list with one text view and a button in each line. The button background is set using some conditions. If I have the number of lines in the list and it scrolls, the background of the button is shuffled. This means that when scrolling, the wrong background is set as the background of the button. How can I solve this problem? My adapter class is below:

    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;
}

In the class PhotoCondtionthreeItemView created a row for the list. (xml is not used for the list line).

Can anybody help me?

thanks

+3
source share
2 answers

call yourListViewadapter.notifyDataSetChanged()when data changes

+1
source

All Articles