You need two classes in your project.
- TabsAdapter which will extend FragmentPagerAdapter implements OnPageChangeListener, TabListener
- A simple class that will extend Fragment. Basically this will contain which fragment to load.
In TabsAdapter class you need to pass in all the data like what all classes you need to load and title of tab like
public TabsAdapter(SherlockFragmentActivity fa, ViewPager vPager) {
// TODO Auto-generated constructor stub
super(fa.getSupportFragmentManager());
context=fa;
ab=fa.getSupportActionBar();
mvPager=vPager;
mvPager.setAdapter(this);
mvPager.setOnPageChangeListener(this);
}
add another method to your TabsAdapter class which will add tabs to your ViewPager
public void addTab(ActionBar.Tab tab,Class<?> clss,Bundle args){
TabInfo info=new TabInfo(clss, args);
tab.setTag(info);
tab.setTabListener(this);
mtabs.add(info);
ab.addTab(tab);
notifyDataSetChanged();
}
and from the activity pass values like :
adap=new TabsAdapter(this,vPager);
adap.addTab(ab.newTab().setText("title of tab"), Fragment_1.class,null);
vPager.setAdapter(adap);
Now customize your tabsadapter class accordingly and use the overriden methods as per your needs.
I hope this small hint is helpful to you.