I have to do some stuff immediately after image has been loaded. I am using SimpleImageLoadingListener
to listen for callback methods, but strangely onLoadingComplete
never gets called, but onLoadingStarted
does. I have checked that there is no call to image loading fail or cancel methods - that means there is no error. Can anyone point out the reason and steps to correct it. Thanks.
public View getView(int position, View convertView, ViewGroup parent) {
ImageView img = new ImageView(mContext);
img.setLayoutParams(new Gallery.LayoutParams(coverflowWidth, coverflowHeight));
img.setScaleType(ScaleType.CENTER_INSIDE);
img.setTag(position);
ImageLoader.getInstance().displayImage(imageURL, img, options, new SimpleImageLoadingListener()
{
boolean cacheFound;
@Override
public void onLoadingStarted(String url, View view) {
List<String> memCache = MemoryCacheUtil.findCacheKeysForImageUri(url, ImageLoader.getInstance().getMemoryCache());
cacheFound = !memCache.isEmpty();
if (!cacheFound) {
File discCache = DiscCacheUtil.findInCache(url, ImageLoader.getInstance().getDiscCache());
if (discCache != null) {
cacheFound = discCache.exists();
}
}
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
//never gets called
ImageView image = (ImageView) view;
if (cacheFound) {
image.setImageBitmap(loadedImage);
}
else
{
ImageLoader.getInstance().displayImage(imageURL, image, options, null);
}
}
});
return img;
}
I was actually making request to load same image 2 times from different places. So onLoadingComplete
was called for another code snippet, not for the one I mentioned above. Silly me... it was a stupid mistake.