Your layout file will display tabs at the top and ViewPager at the bottom, as shown in the code snippet below:
<com.astuetz.PagerSlidingTabStrip android:id="@+id/tabs" app:pstsShouldExpand="true" app:pstsTextAllCaps="true" android:layout_width="match_parent" android:layout_height="48dp"> </com.astuetz.PagerSlidingTabStrip> <android.support.v4.view.ViewPager android:id="@+id/viewpager" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@android:color/white" />
Create fragment
create a fragment [res / layout / fragment_page.xml] and copy and paste this code
<TextView android:id="@+id/tvTitle" android:text="Fragment #X" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" />
In PageFragment.java, define the inflation logic for the fragmented section of the contents of the tab:
public class PageFragment extends Fragment { private int mPage; public static final String ARG_PAGE = "ARG_PAGE"; public static PageFragment newInstance(int page) { Bundle args = new Bundle(); args.putInt(ARG_PAGE, page); PageFragment fragment = new PageFragment(); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mPage = getArguments().getInt(ARG_PAGE); }
Deploy FragmentPagerAdapter
The next thing to do is implement an adapter for your ViewPager that controls the tab order.
public class SampleFragmentPagerAdapter extends FragmentPagerAdapter{ final int PAGE_COUNT = 3; private String tabTitles[] = new String[] { "Tab1", "Tab2", "Tab3" }; public SampleFragmentPagerAdapter(FragmentManager fm) { super(fm); } @Override public int getCount() { return PAGE_COUNT; } @Override public Fragment getItem(int position) { return PageFragment.newInstance(position + 1); } @Override public CharSequence getPageTitle(int position) {
Setting Sliding Tabs
Finally, we need to attach our ViewPager to the SampleFragmentPagerAdapter, and then configure the sliding tabs using a two-step process:
In the onCreate () method of your activity, find the ViewPager and plug in the adapter.
Set ViewPager to PagerSlidingTabStrip to connect tabbed pager.
public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
And this is the result

for more information check out the following link
Luck