0

I have a project with three fragments and I can swipe the fragments horizontally using the View Pager. I want to load the first fragment again after swiping the third fragment.According to my code I can only swipe until the third fragment.To view the first fragment I have to swipe backwards.

I think we have to include a logic here. As I'm new to programming it would be grate if someone can help me.

I have provided the code below.Thank you in advance for any help.

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

public class PagerAdapter extends FragmentPagerAdapter {

    public PagerAdapter(FragmentManager fm) {
    super(fm);
    // TODO Auto-generated constructor stub
    }

    @Override
    public Fragment getItem(int arg0) {
    // TODO Auto-generated method stub
    switch(arg0){
    case 0:
    return new FragmentOne();

    case 1:
    return new FragmentTwo();

    case 2:
    return new FragmentThree();

    default:
        break;
     }
    return null;
   }
   @Override
    public int getCount() {
    // TODO Auto-generated method stub
    return 3;
        }

   }
DHACK
  • 1
  • 3
  • 1
    Possible duplicate of [this](http://stackoverflow.com/questions/7546224/viewpager-as-a-circular-queue-wrapping) or [this](http://stackoverflow.com/questions/11465815/how-to-create-circular-viewpager) – Rehan Aug 26 '16 at 06:32
  • Thanks for the links – DHACK Sep 05 '16 at 05:00

1 Answers1

0
private void scrollViewSecondViewPager() {

    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    if (viewpagersecondcount <= 2) {
                        viewPager.setCurrentItem(viewpagersecondcount);
                        viewpagersecondcount++;
                    } else {
                        viewpagersecondcount = 0;
                        viewPager.setCurrentItem(viewpagersecondcount);
                    }
                }
            });
        }
    }, 500, 3000);

}

call this method on an Oncreat() after 3rd once it will automatically call to first fragment.