0

I have loaded and displayed some image from internet using UIL.

        DisplayImageOptions options = new DisplayImageOptions.Builder()
            .displayer(new CircleBitmapDisplayer(0xFF70C7BE, 2))
            .showImageOnLoading(R.drawable.avatar)
            .showImageOnFail(R.drawable.avatar)
            .showImageForEmptyUri(R.drawable.avatar)
            .cacheOnDisk(true)
            .cacheInMemory(false)
            .imageScaleType(ImageScaleType.EXACTLY)
            .bitmapConfig(Bitmap.Config.RGB_565)
            .build();

    //show image
    ImageLoader.getInstance().displayImage(imgURL, imgAvatar, options);

As you can see from the code, I used a CircleBitmapDisplayer as the displayer, and set showImageOnFail with an image.

The problem I am facing is that the displayer only applied when image load successfully, but not applied when image load failed.

So how can I also apply the displayer to image set in showImageOnFail when image load failed?

Season
  • 1,178
  • 2
  • 22
  • 42

2 Answers2

0

Write your code on onLoadingFailed and onLoadingCancelled.

imageLoader.displayImage(imageUri, imageView, options, new ImageLoadingListener() {
    @Override
    public void onLoadingStarted(String imageUri, View view) {
        ...
    }
    @Override
    public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
        ...
    }
    @Override
    public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
        ...
    }
    @Override
    public void onLoadingCancelled(String imageUri, View view) {
        ...
    }
}, new ImageLoadingProgressListener() {
    @Override
    public void onProgressUpdate(String imageUri, View view, int current, int total) {
        ...
    }
});

for more info see below link :-

https://github.com/nostra13/Android-Universal-Image-Loader

duggu
  • 37,851
  • 12
  • 116
  • 113
  • I know I can set up a listener, what I want to know is how to apply the displayer on to the image at onLoadingFailed – Season Feb 27 '15 at 07:47
  • @Season simple just set drawable on your imageView onLoadingFailed – duggu Feb 27 '15 at 07:50
  • but I've already set showImageOnFail(R.drawable.avatar) in options, shouldn't it works? – Season Feb 27 '15 at 07:51
  • @Season im also confuse why your code not working. for now use this and on rest of part do R&D and update problem solution .... – duggu Feb 27 '15 at 07:56
0

As Duggu suggested, using ImageLoadingListener and apply displayer to bitmap and feed it to ImageView in onLoadingFailed and onLoadingCancelled could somehow solve the problem.

Here is the final code.

        ImageLoader.getInstance().displayImage(final_url, imgAvatar, options, new ImageLoadingListener() {
        @Override
        public void onLoadingStarted(String imageUri, View view) {
            new CircleBitmapDisplayer(0xFF70C7BE, 2).display(BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar), (ImageView)view);
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            new CircleBitmapDisplayer(0xFF70C7BE, 2).display(BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar), (ImageView)view);
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            new CircleBitmapDisplayer(0xFF70C7BE, 2).display(loadedImage, (ImageView)view);
        }

        @Override
        public void onLoadingCancelled(String imageUri, View view) {
            new CircleBitmapDisplayer(0xFF70C7BE, 2).display(BitmapFactory.decodeResource(context.getResources(), R.drawable.avatar), (ImageView)view);
        }
    });

And I've modified the display(...) of CircleBitmapDisplayer to display(Bitmap bitmap, ImageView imageAware)

Season
  • 1,178
  • 2
  • 22
  • 42