FlashAsh80
FlashAsh80

Reputation: 1367

Show single indeterminate progress bar for multiple images being loaded

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.

Upvotes: 0

Views: 1647

Answers (1)

nostra13
nostra13

Reputation: 12407

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);
        }
    }
}

Upvotes: 3

Related Questions