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

one.xml

two.xml

three.xml

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 MainActivity.java class

Go to the mainactivity.java 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 306 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

Leave a Reply

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

GET YOUR EBOOK FOR FREE

Unlock free ebook "Beginning Programming ALL-IN-ONE Desk Reference for DUMMIES" now!

We will send a copy to your email