Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additional check in "instantiateItem" #4

Open
tingyik90 opened this issue May 3, 2018 · 0 comments
Open

Additional check in "instantiateItem" #4

tingyik90 opened this issue May 3, 2018 · 0 comments

Comments

@tingyik90
Copy link

In instantiateItem, we need to add additional check to make sure the fragment retrieved from mFragments is correct.

String fragmentTag = getTag(position); 
if (mFragments.size() > position) {
    Fragment f = mFragments.get(position);
    if (f != null && TextUtils.equals(f.getTag(), fragmentTag)) {
        return f;
    }
}

This is because calling notifyDataSetChanged(), eventually calling getItemPosition(), does not remove the fragment at the end of list.

In my case, A(0), B(1), C(2) are initiated. When deleting B(1), I animate viewpager to move current item to C(2) first. This makes mFragments to be A-destroyed(0), B(1), C-currentItem(2), D-initiated(3).

I then call notifyDataSetChanged() and this return POSITION_NONE for B(1). This updates mFragments to be A-recalled(0), C-currentItem(1), D-reinserted(2), D-not deleted(3). So when I swipe right, a new fragment E(3) was not created. Fragment D-not deleted was recalled and it gave a black screen in viewpager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant