Image Slider With Slideshow Using Viewpager Android Studio Example

Hello, dear developers. In android image slider with slideshow using Viewpager example, you will learn how to create image slider in the Android app.

We will make image slider with circular or dot navigation indicator.

This indicator will guide user which number of image is currently being shown in slider.

You can also call it as a slideshow.

We will use Viewpager to develop this tutorial programmatically.

For images from url, read how to fetch images from url and show in viewpager slideshow.

First, check the output and then we will go on to develop android image slider with slideshow using a Viewpager.

Download Source Code

Creating Android Image Slider With Slideshow Using Viewpager

Step 1: Create a new project in Android Studio.

Make one separate new project in android studio.

Step 2: Updating build.gradle(Module:app) file

Add following code into dependencies{} 

Step 3: Adding Images into Drawable directory

Download and add following images into drawable directories.

Slide_images_demonuts

After adding images, a directory will look like below image.

image slider slideshow viewpager android

drawable directory

Step 4: Creating ImageModel.java class

Create a new class and name it as ImageModel.java and add below code

Step 5: Creating Layout resource for single slide

Create one layout resource file under layout directory and name it as slidingimages_layout.xml

add following code:

Step 6: Preparing Adapter class for Viewpager

Open a new Java class and name it as SlidingImage_Adapter.java

Copy and paste below

Step 7: Updating activity_main.xml file

Copy and paste following

Step 8: Updating MainActivity.java file

Update MainActivity with below source code

Step 9: Stopping Auto Slider

See following code which is responsible for auto sliding of image

If you want to stop automatic sliding of an image, comment out above code.

After stopping auto sliding, user will need to swipe it manually.

We have used Timer class to specify a time interval for each auto sliding.

User can also swipe manually when auto sliding is enabled.

Here images will be slide every 3 seconds. You can change it by updating

3000,3000); values in above source code.

So it was all about image slider with slideshow using Viewpager android example. Thank you.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

31 Responses

  1. Kyle marsh says:

    Very informative and useful. Thanks!

  2. خانه اندروید says:

    hi admin very good post

  3. Wallison Gomes says:

    Hello, Hardik Parsania.
    Execelente project, I really liked it !!!
    How could it be possible to make the images pass randomly rather than in sequence?

    Well I will use around 100 photos, but I did not want them to remain in the same position, I would like them to be random.

    How can I implement this solution?

    Thank you very much for sharing your knowledge !!!

  4. Hardik Parsania says:

    Hello, Thank you for your review.
    You can shuffle arraylist which is passed into the adapter.
    Check: http://stackoverflow.com/questions/16112515/how-to-shuffle-an-arraylist
    http://stackoverflow.com/questions/4228975/how-to-randomize-arraylist

  5. vishal kumar jaiswal says:

    Thanks for this tutorial

  6. Danu Prakoso says:

    is it automatic?

  7. jitendra says:

    nice tutorial

  8. Amol says:

    I want to add Star Rating in image and image and description should come from database,how will i do it please tell me

  9. Rashi says:

    Hello, Hardik Parsania.
    How to fetch the image from server using URL.

  10. Peter says:

    Hi Hardik,
    Great work.
    Can you give an example using Fragment and fragment layout instead of Activity.
    Thanks.

  11. Ajay says:

    can you show how to use this php mysql or firebase

  12. shweta says:

    i want to view same page only data get different using database id, how can i do that using swipe window

  13. Riz says:

    Hi, thanks for great website and great tutorial, i want to ask you if it is possibile to use this slider in card view. thanks

  14. Riz says:

    NO i am unable to do, the images show randomly and sometime the images are loaded more then that i want. For other users you can try don’t trust on me because i am newbie. thanks

  15. star says:

    CirclePageIndicator class is not created ???

    • Hardik Parsania says:

      Did you integrate below line in build.gradle file?
      compile ‘com.github.JakeWharton:ViewPagerIndicator:2.4.1’

      Check out step 2 again

  16. ziddi khattak says:

    how to integrate slide show in url images, i’v list of images link, and i want to do the same like as yours, but don’t know how to do this, please share your experience as soon.. thanks in advance

  17. Amin says:

    hi dear developer , do you exist other way for slideshow?
    that of course without library…
    please navigate me …

    • Hardik Parsania says:

      Library is used to show dots (shows current slide) at the bottom of the slide.
      You can make slide show with viewpager only.

Leave a Reply

Your email address will not be published. Required fields are marked *