Well, what I did pretty quick here, was entirely based on the example I indicated for you in the comment. So for simplicity I suggest following the example start where it mounts ViewPager
.
When you do this, you will only have a Fragment
but with different data, in the ScreenSlidePageFragment class, add a parameter and the constructor passing the page number:
private int position;
public ScreenSlidePageFragment(int position) {
this.position = position;
}
In this same class, in onCreateView
you already have the page number and do what needs to be done, using the database and so on.
Going back now to the ScreenSlidePagerAdapter , you need to pass the page number to your new constructor, so now your adapter :
private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter {
public ScreenSlidePagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return new ScreenSlidePageFragment(position);
}
@Override
public int getCount() {
return NUM_PAGES;
}
}
If you'd like, you can download of this project I've done and test for yourself ( ignore the project name).