How to Add progress bar to ViewPager in Android

Go To


How can I add a progress bar to a ViewPager in Android?

My scenario is that I have to load imageURL's in a ViewPager. When the user swipes the pager, if the ImageURL is not loaded I need to show the progress bar/loading GIF image.

Is it possible?

2012-04-04 07:41
by Kalai Selvan.G
Try to use lazy loading in your scenario.In this stuff use normal priority thread which renders your image in background.Try to use progress dialog rather than progress bar in your case - Shashank_Itmaster 2012-04-04 08:41


I think Satya was thinking to something like this in the following. In your viewpager adapter class you should have this method:

            public Object instantiateItem(View collection, final int position) {

                LayoutInflater inflater = (LayoutInflater) collection.getContext()

                final FrameLayout imageLayout = (FrameLayout) inflater.inflate(R.layout.fotopager_buttons, null);
                final ImageView imageView = (ImageView) imageLayout.findViewById(;
                final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(;

                imageLoader.displayImage(Gallery.get_big_image_url(position), imageView, options, new ImageLoadingListener() {
                    public void onLoadingStarted() {

                    public void onLoadingFailed() {

                    public void onLoadingComplete() {

                views.put(position, iv);

                ((ViewPager) collection).addView(imageLayout,0);

                return imageLayout;

And the R.layout.fotopager_buttons.xml like that:

<?xml version="1.0" encoding="utf-8"?>

    android:adjustViewBounds="true" />


You can see the rest of the imageLoader class here:

2012-04-04 17:15
by Zappescu
This is what i exactly need..bunch thanks my Frien - Kalai Selvan.G 2012-04-06 06:15
Here is an issue am getting runtime exception..Shows that Configuration=nul - Kalai Selvan.G 2012-04-06 08:37
Well, I just posted a piece of the complete code. Let's try to check all the rest in the link attached - Zappescu 2012-04-06 09:07
I downloaded the code from that link..It works fine,but if i add my imageURLS there exists the proble - Kalai Selvan.G 2012-04-06 09:24
@Zappescu the attached link is not valid anymore - Mazen Kasser 2013-10-08 03:24
@mazen here it is the new link: - Zappescu 2013-10-09 06:26


You could try to handle that in your own view rather than tying it up with the viewpager.

2012-04-04 08:27
by Satya
@Sathya: how is that possible could u explain it or some samples there!! - Kalai Selvan.G 2012-04-04 09:50