Android Sliding Pages using ViewPager and Fragment tutorial with example

Most of our readers requested regarding how to make a swipeable pages without any tabs as in most of the apps that provide login or overview of their apps.
So I decided to post how to attain such sliding screens without tabs so that you can use for your login pages, some demo kind of things.Here we are going to use the view pager to attain that and that's a Simple one!

Lets get Started

Layout manager that allows the user to flip left and right through pages of data. You supply an implementation of a PagerAdapter to generate the pages that the view shows.

ViewPager is most often used in conjunction with Fragment, which is a convenient way to supply and manage the lifecycle of each page. There are standard adapters implemented for using fragments with the ViewPager, which cover the most common use cases.
These are FragmentPagerAdapter and FragmentStatePagerAdapter; each of these classes have simple code showing how to build a full user interface with them.

For more you can get through android blog!

You may also like:
Swipe with Tabs in android

Step 1:

The layout file:
Since we are creating fragment we need to create the fragment views.


Simlarly for FragmentLayout2.xml and

Simlarly for FragmentLayout3.xml and

Thats it we have created our fragments, so that it can be used as views to slide.

Step 2:

Now the important part of including viewpager to a layout.In this lyout file i have used external fonts for UI deigning..

create a Viewpager_layout.xml and paste the code as in below

Next we will inflate the fragments using
 public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)

Here is the complete java code for

Similarly we can write the code for

Here is the third .Just copy it and paste it.

You may Also like :
Sliding Navigation in Android

The file where the fragments are added to its component and inflated to UI.

Now to do this we have use PageAdapter

What is Page Adapter?

PagerAdapter is more general than the adapters used for AdapterViews. Instead of providing a View recycling mechanism directly ViewPager uses callbacks to indicate the steps taken during an update. A PagerAdapter may implement a form of View recycling if desired or use a more sophisticated method of managing page Views such as Fragment transactions where each page is represented by its own Fragment.

if you want to explore u can ViewPager
Do subscribe us,Follow us on facebook,Twitter,Support us.

Happy Coding!Happy Development

Hey I'm Venkat
Developer, Blogger, Thinker and Data scientist. nintyzeros [at] I love the Data and Problem - An Indian Lives in US .If you have any question do reach me out via below social media


how to add a listview for each swipw views??

how to add a list for each fragments\listviews in swipeview????

Very thanks for providing the tutorial, awesome!

Really nice composed tutorial !thanks for it

Thank You !! Awesome Blog.
Great knowledge with good concept about Android Development.
I would like to share some useful links for Android Interview Questions and Android Tutorial. Keep share your knowledge with us.