I am trying to use this library in my app:https://github.com/astuetz/PagerSlidingTabStrip
I read the documents but I didn't understand anything.I have two fragments so I want to place two tabs to my app.Where do I put the viewpager xml ?
Where do I put the this code block:
// Initialize the ViewPager and set an adapter
ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(new TestAdapter(getSupportFragmentManager()));
// Bind the tabs to the ViewPager
PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
tabs.setViewPager(pager);
Just main activity or all fragments and main activity ? (I have same question for viewpager xml) Can anyone explain to me how can I implement this to my app step by step ?
Ps:https://github.com/astuetz/PagerSlidingTabStrip/tree/master/sample This is the example code.
I just make it for two tabs as you asked!
0) Add the library to your build path
1) Create your two fragments
and
and their layouts for example can be:
2) Create MainActivity layout:
3) Create your viewpager adapter
3) Assign adapter to your viewpager and the viewpager to the
PagerSlidingTabStrip
at the MainActivity4) Run
Your layout file will have tabs on the top and a ViewPager on the bottom as shown in the code snippet below:
Create Fragment
create fragment [res/layout/fragment_page.xml] and copy and paste this code
In PageFragment.java define the inflation logic for the fragment section of tab content:
Implement FragmentPagerAdapter
The next thing to do is to implement the adapter for your ViewPager which controls the order of the tab.
Setup Sliding Tabs
Finally, we need to attach our ViewPager to the SampleFragmentPagerAdapter and then configure the sliding tabs with a two step process:
In the onCreate() method of your activity, find the ViewPager and connect the adapter.
Set the ViewPager on the PagerSlidingTabStrip to connect the pager with the tabs.
And this is the result
for more information , check out the following link
Good Luck