Q:

View pager skipping to irregular position when I click button in second fragment android?

I am using view pager in activity and the sequence is - when I click the next button in first page, it should go to the second page. If I click the button in second page, it should go to third and so on. But my current app is behaving weird, i.e, When I click next button in second page, it goes to fourth page. Once again when I click first button in first page, it jumps to third page and so on..
Here is code.
public class ViewPagerActivity extends AppCompatActivity {
    private ViewPager pager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.viewpager_act);
        setViewPager();

        /*pager.setPageTransformer(true, new ZoomPageTransformer());

        pager.setAdapter(new MyViewPagerAdapter(getSupportFragmentManager()));
        pager.post(new Runnable() {
            @Override
            public void run() {
                pager.setCurrentItem(position); //don't know how to use this from fragment
            }
        });*/
    }

    private void setViewPager() {
        pager = (ViewPager) findViewById(R.id.viewPager);
        FragmentManager fm = getSupportFragmentManager();
        ViewPagerAdapter adapter = new ViewPagerAdapter(fm);
        pager.setAdapter(adapter);

    }

    public void setCurrentItem(int selectedPosition) {
        pager.setCurrentItem(selectedPosition, true);
    }

    private class ViewPagerAdapter extends FragmentPagerAdapter {
        public ViewPagerAdapter(FragmentManager supportFragmentManager) {
            super(supportFragmentManager);
        }

        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return FirstPager.newInstance();
                case 1:
                    return SecondPager.newInstance();
                case 2:
                    return ThirdPager.newInstance();
                case 3:
                    return FourthPager.newInstance();
                case 4:
                    return FifthPager.newInstance();
                case 5:
                    return SixthPager.newInstance();
                default:
                    return null;
            }

        }

        @Override
        public int getCount() {
            return 6;
        }
    }

FirstPager:
public class FirstPager extends Fragment {
    private ImageView slideArrow;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.first_pager, container, false);
        return v;
    }

    public static FirstPager newInstance() {
        FirstPager fragment = new FirstPager ();
        return fragment;
    }
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initUI();
    }

    private void initUI() {
        slideArrow = (ImageView) getActivity().findViewById(R.id.next_arrow);
        slideArrow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((ViewPagerActivity)getActivity()).setCurrentItem (1);
            }
        });
    }
}

Similarly in other fragments, I gave currentItem as 2,3,4,5 and 6. But it’s position behavior is not correct.
I referred some post but how in my case, how I will apply for a method to pass from fragment to make the position to work correctly?

A:

I think the best approach would be this:
  viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);

