I am creating detail fragments from an ArrayList of objects, the ArrayList is a representation of a ListFragment. I am using a FragmentStatePagerAdapter to manage each detail page (fragment). Here's the code for my FragmentActivity's FragmentStatePagerAdapter inner class
public static class DetailPagerAdapter extends FragmentStatePagerAdapter {
public DetailPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int i) {
if (BuildConfig.DEBUG) {
Log.e(Constants.TAG, "DetailPagerAdapter creating DetailFragment - item " + i );
}
Fragment fragment = new DetailFragment();
// get object from outer class ArrayList
Object fobject = detailslist.get(i);
final Detail fDetail = (Detail)fobject;
Bundle args = new Bundle();
args.putInt(DetailFragment.ARG_POSITION, i + 1);
args.putString("detailTitle",fDetail.getDetailName());
fragment.setArguments(args);
return fragment;
}
@Override
public int getCount() {
// object collection same size as list
return detailslist.size();
}
@Override
public CharSequence getPageTitle(int position) {
return "Position #" + (position + 1);
}
}
This creates all the detail fragments but it always shows the user the first ListFragment entry. I can swipe forwards and backwards OK. If the user selects an an item from the ListFragment and if that item is in the middle of the list I want to position to that detail object instance. I also want the user to be able to swipe back and forward to the other detail pages. I pretty sure I need to use the FragmentManager transaction methods but I not sure how to use it when using a FragmentStatePagerAdapter. Anybody got any pointers?