I am using the method suggested here in order to implement swipeable tabs in Android using the SupportV4 library. In order to initialise the ViewPager, one has to create a page adapter which needs to be filled with a list of fragments/tabs, each associated with an activity, as shown here:
/**
* Initialise ViewPager
*/
private void intialiseViewPager() {
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this, Tab1Fragment.class.getName()));
fragments.add(Fragment.instantiate(this, Tab2Fragment.class.getName()));
fragments.add(Fragment.instantiate(this, Tab3Fragment.class.getName()));
this.mPagerAdapter = new PagerAdapter(super.getSupportFragmentManager(), fragments);
this.mViewPager = (ViewPager)super.findViewById(R.id.viewpager);
this.mViewPager.setAdapter(this.mPagerAdapter);
this.mViewPager.setOnPageChangeListener(this);
}
My question is: how can I dynamically populate the fragments list with tabs not associated with any class. For example a list of tabs in which the header of the tabs are obtained from an string array