Android Slider ViewPager Tutorial

Android ViewPager allow the user to swipe left or right for navigate to another page or view in the android application. It mostly use to combine with fragments because it let the user switch to another fragment just swipe by finger. In this tutorial, I will give you some viewpager tutorial steps in the android application. If you are beginner, you are in the right place.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “ViewPagerExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Activity” and Click Next button
5. Lastly, press finish button.

Add a New Class

Right click the package name and add the new class name as “ViewPagerAdapter”.

Edit class

Go to the file and edit to the source code below. This class should be extends to the pageradapter.

Add 3 diferent xml layout

Go to res > right click layout > new >layout resource file. First recource file name is one, second is two, the last xml is three.

Edit one,two, three.xml layout

Go to those 3 file and edit to the following code. I change all the relativelayout to the linearlayout and add one textview inside it.




Edit mainactivity.xml layout

Add 2 image in drawable folder

Add two indicator image to your drawable folder by copy the image and paste it into the folder.

Edit class

Go to the class and edit to the following code.

Run your project

You now can run your project in the android emulator. You able to use the viewpager ability in the android application.

(Android ViewPager)

Source Code

(Visited 503 times, 1 visits today)

Yong Loon Ng

Ng Yong Loon, better known as Kristofer is a software engineer and computer scientist who doubles up as an entrepreneur.

You may also like...

Leave a Reply

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