0

I've written this class that extends FragmentStatePagerAdapter in order to swipe between views. Now I need to make the swiping list circular so that swiping after the last fragment would display the first fragment. I haven't found a way to properly do that, any help?

Here's the code of the adapter:

public class DetailsPagerAdapter extends FragmentStatePagerAdapter {

List<Detail> details=null;

public DetailsPagerAdapter(FragmentManager supportFragmentManager, List<Detail> details) {
    super(supportFragmentManager);
    this.details=details;
}

@Override
public Fragment getItem(int i) {
    System.out.println("Fetching item at position "+i);
    Fragment fragment = new DetailsFragment();

    Bundle args = new Bundle();
    args.putString("img",details.get(i).getImageFileName());
    args.putString("desc",details.get(i).getDescription());
    fragment.setArguments(args);
    return fragment;
}

public int getCount() {
    return details.size();
}

}

wallen
  • 311
  • 1
  • 4
  • 13
  • Have a look at [`InfiniteViewPager`](https://github.com/antonyt/InfiniteViewPager), which is supposed to do what you're after. – MH. May 05 '13 at 19:08

1 Answers1

2

in your Adapter, try something like that

        @Override
        public Fragment getItem(int pos) {
            pos = pos % details.size();
            ....
        }

        @Override
        public int getCount() {
            return  99999;
        }
Mohammad Ersan
  • 12,304
  • 8
  • 54
  • 77
  • I am not sure that something like this would work. I tried playing with the first operand but as expected getCount() would return values in [0,details-size()-1] range which would just shorten the collection of my objects and only display a subset of the fragments I want to show. – wallen May 05 '13 at 19:10
  • please wait, ill fix my answer, i was dizzy when i wrote this answer :) – Mohammad Ersan May 06 '13 at 08:37