Android FragmentPagerAdapter Circular listview

177 views Asked by At

I want to create a circular listview in android, however I'm using/extending FragmentPagerAdapter and I want to check the item position in order to check the next item in circular listview.

I just want to develop a infinite listview which will repeat itself when the scroll ends.

My Code:

private class ListPageAdapter extends FragmentPagerAdapter {

    private String[] items={"Item1","Item2","Item3","Item4", "Item5", "Item6", "Item7", "Item8"};
    public ListPageAdapter(FragmentManager fm) {
        super(fm);
    }

    @Override
    public Fragment getItem(int i) {
        Fragment sampleFragment=new SampleFragment();
        Bundle bundle=new Bundle();
        bundle.putString("text","FragmentNumber"+i);
        sampleFragment.setArguments(bundle);
        return sampleFragment;
    }

    @Override
    public int getCount() {
        return items.length;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return items[position];
    }

}

How I can make the Item1 after Item8 to make it a circular listview?

1

There are 1 answers

2
Laurent Meyer On

What about something like:

bundle.putString("text","FragmentNumber"+(i % items.length));

I didn't test it but I would say that it could work :D