ViewPager with dynamic contents


Staff member
I am using the method suggested <a href="" rel="nofollow">here</a> 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&lt;Fragment&gt; fragments = new Vector&lt;Fragment&gt;();
    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(;

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