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.

You can also call it as a slideshow.

We will use Viewpager to develop this tutorial programmatically.

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.

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

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

Leave a Reply

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