Here is the situation :
I, by default have one Page item : The "ADD" page item.
Then after I reload the database, I may add more than 1 page at a time.
Maybe that's not the problem, the proble is that the two added pages are
before my existing page.
notifyDataSetChanged() is call from the FragmentPagerAdapter and the page
that was the first and only is now the third.
I swap back at the second page and everything is fine but when swapping to
the first page, here is the problem.
java.lang.IndexOutOfBoundsException: Invalid index 2, size is 2
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)
Here is the capture when I was on the debugger. I added some values from
the variables inspector and watches.
@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) { // The position's value
here is 2
mSavedState.add(null);
} // HERE mSavesState.size() = 3; it did "expand" correctly
mSavedState.set(position,
mFragmentManager.saveFragmentInstanceState(fragment));
*137:* => mFragments.set(position, null); // Here is the problem, the
position is 2 but the mFragments.size() is 2 so I got out of bounds.
mCurTransaction.remove(fragment);
}
mFragments.size() may be verified at the beginning => if(position >=
mFragments.size()) => mFragment need to be adapted.
or maybe somewhere else, the new size of the adapter.getCount() may be use
to prevent this.
Thanks
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/c98c8de2-db60-4986-9912-926023de61f5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.