Reputation: 486
I was looking at the example of the FragmentStatePagerAdapter at http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html
public static class MyAdapter extends FragmentStatePagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public Fragment getItem(int position) {
return ArrayListFragment.newInstance(position);
}
}
I've also looked around at other posts in stackoverflow, but I am still unsure as to how to add/remove pages from the fragmentStatePagerAdapter, and also how exactly the getItem method is called. So if I were looking to add a method to MyAdapter to add pages, how would that be done? Or is that not the standard way of adding pages? Any information is appreciated.
Upvotes: 1
Views: 1467
Reputation: 28179
After adding the new item you'll need to call myAdapter.notifyDataSetChanged();
Also, it seems you use a const for the number or items NUM_ITEMS
, you'll need to change that to something dynamic you can change.
Upvotes: 1