Tag Archives: swipe view

feature_image

Hello all, How are you? Today I am going to show you one of the easiest way to do Swipe View within Tab Layout in an android application,also called View Pager when we slide or swipe the page of Android Application.
It is really very helpful to show information in front and transition between two or more activity is very easy.So lets dig inside how to create this project –
First of all take or create your project and give desire name you want.In this project we going to use View Pager within Tab Layout so that both work together and final output will become so cool and easy.
Whenever we want to use two different layout within a single layout we will use Layout Inflator and we will approach this technique via fragments.
You can checkout the final output here and move further towards coding part –

Download Code

Now Lets start with designing part and in your activity_main.xml you have to take supportable view pager like –

activity_main.xml

Now create your different Tabbing activities here I am going to use three xml files for Movie,Music and Video sections. So create all you want to show .

movie_frag.xml

music_frag.xml

Video_frag.xml

Now lets move to coding or my best Java part you have to make TabPagerAdapter class for Tabs , so that if you select any Tab which class should call like if I tab Movie Tab then its corresponding class i.e. Movie.java will call.This class should extends FragmentStatePagerAdapter class to use the features of fragments.

TabPagerAdapter.java

Now on getItem() we choose can choose different class so create those classes also Movie.java,Music.java and Video.java.This class should extends Fragments.

Movie.java

Music.java

Video.java

Now You have to make or create your MainActivity.java in which you will call TabPagerAdapter class object and set it in to your project .It should extends FragmentActivity class.

One more thing we going to use ActionBar and set the tabs over it so we also going to call ActionBar class .

MainActivity.java

Make sure you have set proper Id’s and extends proper classes , and Run your  Project and you will feel the awesome response .

Output-

screen_outputFeel free to ask your queries and errors , will solve it. Thank You ! Happy Coding :p