I am using a ViewPager with FragmentStatePagerAdapter to display images. I am able to successfully display images and now I am trying to implement "infinite scrolling". "Infinite scrolling" means that I am able to loop to the first image once I reach the last image & and I am to loop to the last image from the first image. Below is an illustration of "infinite scrolling" for clarification.
"infinite scrolling" : (... C <-> A <-> B <-> C <-> A ... )
My code implementation of this is below:
/* PagerAdapter class */
public class SlidePagerAdapter extends FragmentStatePagerAdapter {
private int urlPicArryIndex = 0;
public SlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return NUM_ITEMS;
}
@Override
public Fragment getItem(int position) {
System.err.println("orignal position = " + position);
position = position % urlPicArray.size();
urlPicArryIndex = position;
System.err.println("urlPicArryIndex = " + urlPicArryIndex);
System.err.println("position = " + position + ", NUM_ITEMS = " + NUM_ITEMS);
return PictureSectionFragment.newInstance(position, urlPicArray.get(urlPicArryIndex));
}
}
Here are what variables are set to that is not displayed in the code snippet above:
NUM_ITEMS is set to 800
urlPicArray is an arrayList of images set in another method.
My code works for "infinite scrolling", however, I am concerned that this is not efficient. By setting NUM_ITEMS to 800 does this set aside this large amount of fragment space in memory? BTW I realize that this is not truly infinite scrolling, however, it should be sufficient for most real world use cases.
I am a just getting into android dev so any help / guidance would be greatly appreciated!