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

InfinteViewPager crashing when updating viewpager with new set of content #32

Open
SumiGhosh opened this issue Jul 1, 2015 · 4 comments

Comments

@SumiGhosh
Copy link

Hi,

When i am updating the viewpager with new set of content and calling notifyDataSetChanged, the app getting crashed.

Below is the logcat details:

java.lang.IndexOutOfBoundsException: Invalid index 10, size is 4
        at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
        at java.util.ArrayList.set(ArrayList.java:481)
        at android.support.v4.app.FragmentStatePagerAdapter.destroyItem(FragmentStatePagerAdapter.java:137)
        at in.jackson.goopa.MainActivity$CustomViewPagerAdapter.destroyItem(MainActivity.java:771)
        at in.jackson.goopa.customlib.InfinitePagerAdapter.destroyItem(InfinitePagerAdapter.java:70)
        at android.support.v4.view.ViewPager.setAdapter(ViewPager.java:417)
        at in.jackson.goopa.customlib.InfiniteViewPager.setAdapter(InfiniteViewPager.java:78)
        at in.jackson.goopa.MainActivity$DilBackgroundService$1.run(MainActivity.java:435)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:193)
        at android.app.ActivityThread.main(ActivityThread.java:5304)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
        at dalvik.system.NativeStart.main(Native Method)
@SumiGhosh
Copy link
Author

How to update new set of data with the library?

@SumiGhosh
Copy link
Author

For now, i just cloned the FragmentStatePagerAdapter and changed the code as below for destroyItem

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
    Fragment fragment = (Fragment)object;

    if (mCurTransaction == null) {
        mCurTransaction = mFragmentManager.beginTransaction();
    }
    /*if (DEBUG) Log.v(TAG, "Removing item #" + position + ": f=" + object
            + " v=" + ((Fragment)object).getView());*/
    while (mSavedState.size() <= position) {
        mSavedState.add(null);
    }
    if(mFragments.size()>position){
        mSavedState.set(position, mFragmentManager.saveFragmentInstanceState(fragment));
        mFragments.set(position, null);

        mCurTransaction.remove(fragment);
    }
}

Currently it just working as it required.

@daviwiki
Copy link

Thanks!, this review help me a lot.

@caizhixing
Copy link

Thanks! This method inspired me.

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

3 participants