1

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.

user1549672
  • 486
  • 1
  • 6
  • 16
  • if i need to remove a page from my adapter, i normally delete it from the database and call the adapter to refresh. Also a Broadcastreceiver can come in pretty handy to inform the proper parts of the code of the changes. – bofredo Aug 07 '13 at 14:32
  • I'm trying to have another page added and populated with data when a button is pressed. Is that possible? – user1549672 Aug 07 '13 at 15:15

1 Answers1

1

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.

marmor
  • 27,641
  • 11
  • 107
  • 150
  • can you help http://stackoverflow.com/questions/40149039/recyclerview-display-only-last-arraylist-item-in-fragment – albert Oct 21 '16 at 07:08