For anyone who wants to know how I managed to do it, here is my code:
Note, I have not created an endless viewpager, instead after carefully looking at various other, I have discovered they also did not create an endless ViewPager themselves, instead opting for a very long total pages.
Below is my ViewPagerAdapter which extends FragmentStatePagerAdapter. Looking at the documents for android, this was recommended when using loads of fragments.
public class ViewPagerAdapter extends FragmentStatePagerAdapter {
private Fragment1 frag1 = new Fragment1();
static final int PAGE_NUM_ITEMS = 7321;
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return frag1.newInstance(position);
}
@Override
public int getCount() {
return PAGE_NUM_ITEMS;
}
}
In my fragment class the code is:
public Fragment1 newInstance(int page){
Fragment1 frag1= new Fragment1();
return frag1;
}
Then setting the viewpager to the middle of the pages, which I believe is 3660 as Java starts at 0.