0

So I have a ListView that has several ImageViews in each list item. I use the Universal Image Loader to load each image.

What I want is to show a single indeterminate progress bar spinner (say on the actionbar), while all the images in the list are loading, and when the last image has loaded the spinner is hidden.

I am not sure if this is possible, or the best technique for doing this?

Thanks.

FlashAsh80
  • 1,357
  • 1
  • 16
  • 27
  • I have pretty much done what's written for the answer [in this post](http://stackoverflow.com/questions/13653816/show-indeterminate-progressbar-while-loading-image-with-universal-image-loader). The only issue is that with this solution, each image is tied to it's own spinner. I want one progress spinner to illustrate the loading of all items. – FlashAsh80 Feb 05 '13 at 23:54

1 Answers1

3

Try this. In adapter:

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    ...     
    ImageLoadingListener listener = new CombinedImageLoadingListener(3, progressBar);
    imageLoader.displayImage(uri1, imageView1, listener);
    imageLoader.displayImage(uri2, imageView2, listener);
    imageLoader.displayImage(uri3, imageView3, listener);
    ...
}

And this listener:

class CombinedImageLoadingListener extends SimpleImageLoadingListener {

    private int imageCount;
    private ProgressBar progressBar;

    public CombinedImageLoadingListener(int imageCount, ProgressBar progressBar) {
        this.imageCount = imageCount;
        this.progressBar = progressBar;
    }

    @Override
    public void onLoadingComplete(Bitmap loadedImage) {
        imageCount--;
        if (imageCount == 0) {
            progressBar.setVisibility(View.GONE);
        }
    }
}
nostra13
  • 12,377
  • 3
  • 33
  • 43
  • 1
    Also consider a case when one of image loading is failed and `onLoadingFailed()` callback can be got. – nostra13 Feb 06 '13 at 14:04