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.

Our App

Now you can use demonuts app to learn anywhere anytime.

App with rich features like search, categories and Bookmarks.

Download here :

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

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.


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

image slider slideshow viewpager android

drawable directory

Step 4: Creating class

Create a new class and name it as 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

Copy and paste below

Step 7: Updating activity_main.xml file

Copy and paste following

Step 8: Updating 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.

Download Source Code

[sociallocker]Download Demo [/sociallocker]

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...

52 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.

  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.

  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.

  18. sszj says:

    hello I want to set different timer for each image is it possible and how where should I apply changes for that.

    • Hardik Parsania says:

      Yes it is possible.
      For that you need to change the code of step 9.
      Here, change the value of handler (3000,3000) according to the currentPage.

  19. sakthi says:

    Program type already present:$1.
    I am getting this error.

  20. Sushma says:

    i replaced it with bitmap.But in adater i am getting setImageBitmap(bitmap) as null object reference, even though the bitmap is not null.
    Please help me with this.

  21. Shahid says:

    Error: Program type already present:$Op

  22. shekib says:

    Thanks Dear sir
    it is working well
    how can make under it menu with imageview

  23. ertugrul says:

    Program type already present:
    Message{kind=ERROR, text=Program type already present:, sources=[Unknown source file], tool name=Optional.of(D8)}

  24. Pranav Mudgil says:

    Im getting this error on mPager and indicator that it is null point reference

  25. Trupti says:

    thanks sir which i got perfect slider coding thanks

  26. Endryck says:

    I put an activity before the sliding starting, leaving and entering in the page, it does not respect the time limit and begins to pass quickly without stopping.

  27. Zawar Ahmad says:

    Im geting this warning while sycn project:
    WARNING: Configuration ‘compile’ is obsolete and has been replaced with ‘implementation’ and ‘api’.
    It will be removed at the end of 2018. For more information see:
    Affected Modules: app

    when i try to build it fails.kindly send updated compile link on my email.

    • Hardik Parsania says:

      Just replace compile with “implementation” in gradle file.

      • james says:

        ERROR: Could not find method implementation() for arguments [com.github.JakeWharton:ViewPagerIndicator:2.4.1] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

  28. Nikolaus says:

    Morning Sir,i want to make image slider but i want to pick the image from my gallery storage ,can you tell me how to do that?

  29. vyshnavi says:

    Thank you for your tutorial.

    i want to get this images from firebase.please tell me how to do that.

  30. imran says:

    hi this is realy great work… am newbee on development. so its realy cool tutorial for every1.

    but i hv a question… how can i make those pictures show fully with in its place

Leave a Reply

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