1

Okay, the problem is almost the same with this post, but the solution there didn't solve my problem.

I use FragmentPagerAdapter with a List holding the Fragments like the below shown.

public class ViewPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;

    public ViewPagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

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

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

    ...
}

And my Fragment overrides the onCreateView method like this.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) {
    return inflater.inflate(theLayoutResourceId, container, false);
}

If using the method in this post (override int getItemPosition(Object object) to return POSITION_NONE), I'll get java.util.ConcurrentModificationException after calling notifyDataSetChanged().

The method call flow is like this.

  1. at ViewPager page index 1, open a Dialog via clicking a Button (just the same as the LoginButton in the Facebook Android example)
  2. after the dialog closed (onAuthSucceed), remove ViewPager page index 1 and and add another page to be page index 1
  3. force update using notifyDataSetChanged

I've tried many other ways to remove a Fragment before adding a Fragment to the adapter, but the page will not update to the new content.

I just found one method to make the page blank...

viewpager.removeViewAt(1);
viewpagerAdapter.removeItem(1);
viewpagerAdapter.addItem(1, new Fragment(...));

Either solving the updating problem or java.util.ConcurrentModificationException would be great. Thanks for your help :)

Community
  • 1
  • 1
Yi H.
  • 299
  • 5
  • 14
  • 1
    hello. could you find a solution for that problem? I have the exact same problem but can't find any working solution for me :( please help if you have something which works! thank you :) – Dominik Mar 19 '12 at 11:52
  • No, I didn't solve the problem, either. – Yi H. Mar 23 '12 at 09:10

1 Answers1

2

This post is kind of old, but in case anyone runs into this. I found the answer in a similar post here. It looks like you are on the right track but you need to change your FragmentPagerAdapter to a FragmentStatePagerAdapter and override the getItemPosition(Object), as you suggested in your post.

Best of luck to you.

Community
  • 1
  • 1
SyntaxRules
  • 2,056
  • 23
  • 32
  • 1
    Thanks. I've tried your method and it did worked, but it is still sometimes weird. I think it is because I'm trying to remove the current viewable page, and the behavior depends on the position of the current page. I think it might be solved by switching the current page out of the screen before removing it but I haven't tried it. – Yi H. Apr 05 '13 at 16:22