Android: ViewPager gets stuck in between views

后端 未结 8 1382
天命终不由人
天命终不由人 2021-02-02 11:30

I have a ViewPager which swipes between Fragments. I\'m using a FragmentStatePagerAdapter to feed the Fragments to the ViewPager. If the user swipes left at a normal pace, and t

8条回答
  •  萌比男神i
    2021-02-02 12:08

    For now, I suspect two methods.

    1) In the fragment code:

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

    Note: getCount() should return the number of fragments instead of the size of the list. I could not tell how many of fragments you will have. Perhaps you have to keep track in the Adapter.

    2) Another, I suspect getItem() method and the use of newInstance(). The related specific code:

    FragmentProfile fragment = FragmentProfile.newInstance(mBagels.get(i),...
    

    Notes:

    • According to Google webpage FragmentStatePagerAdapter, method newInstance should create a new fragment probably because that's when the FragmentStatePagerAdapter does not have the fragment in memory yet OR was released from memory.

    • Perhaps post the code related to FragmentProfile.newInstance especially if you disagree with my statement above.

提交回复
热议问题