I am using nostra13 universal image loader to load images from api of different social medias. Following is the code of my adapter class.
imageLoader.displayImage(objects.get(position).getFeedImageUrl(),viewHolder.image, defaultOption, new SimpleImageLoadingListener() {
@Override
public void onLoadingStarted(String imageUri, View view) {
viewHolder.spinner.setVisibility(View.VISIBLE);
}
@Override
public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
String message = null;
switch (failReason.getType()) {
case IO_ERROR:
message = "Input/Output error";
break;
case DECODING_ERROR:
message = "Image can't be decoded";
break;
case NETWORK_DENIED:
message = "Downloads are denied";
break;
case OUT_OF_MEMORY:
message = "Out Of Memory error";
break;
case UNKNOWN:
message = "Unknown error";
break;
}
Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
viewHolder.spinner.setVisibility(View.GONE);
}
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
viewHolder.spinner.setVisibility(View.GONE);
}
});
}
The problem is that I show the spinner visible when the photo is loading and in onLoadingComplete
.I set the visibility gone but still the spinner is visible when photo loading completes. As i scroll my list and come back to the same position then only the spinner visibility goes away.
Initialization of image loader in the constructor is as follows.
public MyAdapter(Context context, ArrayList<Model> objects) {
// TODO Auto-generated constructor stub
this.objects=objects;
this.context=context;
defaultOption = new DisplayImageOptions.Builder()
.resetViewBeforeLoading(true)
.showImageForEmptyUri(R.drawable.whitebackground)
.showStubImage(R.drawable.whitebackground)
.showImageOnLoading(R.drawable.whitebackground)
.imageScaleType(ImageScaleType.EXACTLY)
.bitmapConfig(Bitmap.Config.RGB_565)
.considerExifParams(true)
.displayer(new FadeInBitmapDisplayer(300))
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
.threadPriority(Thread.MAX_PRIORITY)
.defaultDisplayImageOptions(defaultOption)
.tasksProcessingOrder(QueueProcessingType.FIFO)
.build();
ImageLoader.getInstance().init(config);
imageLoader = ImageLoader.getInstance();
mFont = Typeface.createFromAsset(context.getAssets(), "Beatles Light Light.ttf");
}