0

I am using FragmentStatePagerAdapter in my app. My problem is that when I am doing notifyDataSetChanged() it's calling only the getCount() and not the getItem(). the getCount is not returning 0. this is my FragmentStatePagerAdapter:

private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {

    public ScreenSlidePagerAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList.size();
    }
}

How could it be that after pagerAdapter.notifyDataSetChanged(); only the getCount() is called and the getItem(int position) is not being called after it? Thanks!

roiberg
  • 13,629
  • 12
  • 60
  • 91

1 Answers1

0

From Issue 19001, I found that int getItemPosition(Object object) needs to be implemented in the FragmentStatePageAdapter subclass. By default this method is assumed to return POSITION_UNCHANGED which will not trigger getItem to be called. However, I, also, ran into issues (possible bugs in the android support library) when I implemented anything other than return POSITION_NONE.

Snippet from my adapter:

@Override
public Fragment getItem(int position) {
    return DiceRollerFragment.instantiate(position);
}
Slobodan Pejic
  • 522
  • 3
  • 9