Android Image Slider Using ViewPager Example

In this tutorial you will learn to make android image slider using ViewPager and PagerAdapter.

ViewPager is a layout manager that allows the user to flip left and right through pages of data. We supply an implementation of a PagerAdapter to generate the pages that the view shows.

Below example shows how to make a simple image slider in android.

Demo

Android Image Slider Using ViewPager Example (Demo)

Android Image Slider Using ViewPager Example

Create an android studio project with package name com.androidimageslider.

Here I have used total 4 pages in slider. So paste some images in res/drawable folder.

Add following code in respective files.

res/layout/activity_main.xml

res/layout/item.xml

src/MainActivity.java

src/MyCustomPagerAdapter.java

Save and run the project.

Screenshot

Android Image Slider Using ViewPager Example

Comment below if you have any doubts regarding above android image slider tutorial.

15 thoughts on “Android Image Slider Using ViewPager Example

  1. priya sharma

    how to set image slider picture change automatically after some delay

    Reply
  2. Tejas Gawali

    Hi Neeraj Mishra Very nice article helpful can you help me with 3 sec timer automatic silder.

    thanks.

    Reply
  3. Abhishek sharma

    when i run the app then it show this error
    Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException:

    Reply
  4. danni

    Got error:package R does not exist.

    Please advice.
    Thanks.

    Reply
  5. RECK

    Hi Neeraj Mishra Very nice article helpful can you help me with 3 sec timer automatic silder.

    Reply
  6. alper

    Hi sir .
    I have a question .How to save the shown image and than pass it to another activity .

    Reply
  7. ankit

    hi sir the app crashes as soon as i open. Kindly help me out

    Reply
  8. htd.com

    i have to say thanks to you Mr. Neeraj Mishra, your code is very useful to my project in AS. GOD bless you

    Reply
  9. Shailesh H Vishwase

    Nice tutorial Neeraj, It is very useful for informative screens like ‘Take a tour’.
    Suppose we want to show fragments instead of images, for that Shall we use FragmentPagerAdaper?

    I have used FragmentPagerAdaper before, but there is one issue with that, after sliding 1st page, screen get flashed. I didn’t get any error, but curiosity to solve that. Will you please help me for that?

    Thanks in advance.
    Shailesh

    Reply
  10. ghasem

    hi, thanks for this tutorial
    i want use database in my app and get image from db … how do it !?
    please help me !

    Reply
  11. Nitin

    when i run the app then it show the error in below code and app crashes when opened
    imageView.setImageResource(images[position]);

    Reply
  12. Manikandan

    Hi neeraj,
    I want my firebase images to be displayed like the one above.is it the same thing the one you coded
    Have retriving the image with glide with images as img1,img2,img3.what changes has to do from the above code.

    Thanks in advance
    Manikandan

    Reply

Leave a Reply

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