I'm using UIL to load images from URL to Gridview, but the problem is that images and items get duplicated or loaded on many wrong positions.
the item that is half way off-screen gets duplicated.
this is the GridView Adapter:
public class GridViewAdapter extends BaseAdapter {
private Activity _activity;
private ArrayList<Object_Wallpaper> wallpapersList;
private ImageLoader mImageLoader;
GridViewAdapter adapter;
ViewHolder holder;
Object_Wallpaper wall;
public GridViewAdapter(Activity activity, ArrayList<Object_Wallpaper> wallpapersList,
int imageWidth) {
this._activity = activity;
this.wallpapersList = new ArrayList<Object_Wallpaper>();
this.wallpapersList = wallpapersList;
this.adapter = this;
this.mImageLoader = ImageLoader.getInstance();
}
@Override
public int getCount() {
return this.wallpapersList.size();
}
@Override
public Object getItem(int position) {
return wallpapersList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
/*private view holder class*/
private class ViewHolder {
ImageView smallThumb;
ProgressBar pb;
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
holder = new ViewHolder();
if (convertView == null) {
LayoutInflater inflater = _activity.getLayoutInflater();
convertView = inflater.inflate(R.layout.grid_item_photo, null);
holder.smallThumb = (ImageView) convertView.findViewById(R.id.imgThumbnail);
holder.pb = (ProgressBar) convertView.findViewById(R.id.progressBar1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
wall = wallpapersList.get(position);
showImage(position);
return convertView;
}
private void showImage(final int position){
if(!wall.isDownloaded){
mImageLoader.displayImage(wall.smallURL, holder.smallThumb, null,
new ImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
holder.pb.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view,
FailReason failReason) {
holder.pb.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
holder.pb.setVisibility(View.GONE);
wall.isDownloaded = true;
wallpapersList.set(position, wall);
}
@Override
public void onLoadingCancelled(String imageUri, View view) {
}
}, new ImageLoadingProgressListener(){
@Override
public void onProgressUpdate(String imageUri, View view,
int current, int total) {
holder.pb.setProgress(Math.round(100.0f * current / total));
}
});
} else {
mImageLoader.displayImage(wall.smallURL, holder.smallThumb);
holder.pb.setVisibility(View.GONE);
}
}
}
And this is the object:
public class Object_Wallpaper implements Serializable {
private static final long serialVersionUID = 1L;
public String id,title,tags,fullResURL, thumbURL, smallURL;
public boolean isDownloaded;
public Object_Wallpaper(String id, String title, String tags,
String fullResURL, String thumbURL, String smallURL) {
this.id = id;
this.title = title;
this.tags = tags;
this.fullResURL = fullResURL;
this.thumbURL = thumbURL;
this.smallURL = smallURL;
this.isDownloaded = false;
}
}
can you tell me what things have I done wrong so far please? thanks. I saw same questions elsewhere, but they didn't help either.
EDIT:
I realized that this happens only in fast scroll. what should I do?