title: change FragmentPagerAdapter adapter position on fragment button click
body: <p>I am working on Android application. In my app I have to use 5 fragment and swipe from fragment 1 to 5. SO I used one FragmentActivity ,FragmentPagerAdapter and 5 fragments. 
  Now I can swipe through all the fragments and can identify the current fragment by using</p>
  
  <pre><code>ViewPager.OnPageChangeListener()
  </code></pre>
  
  <p>I have to add buttons in all the fragments and button click must open the next fragment like swipe. How could I do this? Here I am posting some of my code snippets.</p>
  
  <pre><code>fragmentactivity.java
  
  public class HomeScreen extends FragmentActivity 
  {
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.themed_circles);
  
      mAdapter = new InsuranceFragmentAdapter(getSupportFragmentManager(),
              HomeScreen.this);
      mPager = (ViewPager) findViewById(R.id.pager);
      mPager.setAdapter(mAdapter);
      mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
      mIndicator.setViewPager(mPager);
      // mIndicator.setCurrentItem(2);
  
      mIndicator
              .setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                  private int pos;
  
                  @Override
                  public void onPageSelected(int position) {
  
                  }
  
                  @Override
                  public void onPageScrolled(int position,
                          float positionOffset, int positionOffsetPixels) {
  
  
                  }
  
                  @Override
                  public void onPageScrollStateChanged(int state) {
                      System.out.println("test scroll state" + state);
  
                  }
              });
  }
  
    }
  </code></pre>
  
  <p>The following is my FragmentPagerAdapter  for swiping fragments.</p>
  
  <pre><code>FragmentPagerAdapter.java
  
  
  public class InsuranceFragmentAdapter extends FragmentPagerAdapter {
  Context contx;
  
  
  public InsuranceFragmentAdapter(FragmentManager fm, Context ctx) {
  
      super(fm);
      this.contx = ctx;
  
  
  }
  
  @Override
  public Fragment getItem(int position) {
      Fragment fragment = null;
      switch (position) {
      case 0:
          fragment = Fragment.instantiate(contx, com.lic.fragments.FragmentBasicPersonal.class.getName());
          break;
  
      case 1:
          fragment = Fragment.instantiate(contx, com.lic.fragments.FragmentationNomineeDetails.class.getName());
          break;
  
      }
  
      return fragment;
  }
  
  @Override
  public int getCount() {
  
      return 2;
  }
  
  
  
  public void setCount(int count) {
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and one of my fragment is the following.
      fragment_one.java</p>
  
  <pre><code>public class FragmentFemale extends Fragment {
  
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
  
     }
  
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View layout = inflater.inflate(R.layout.fragment_female_husband, container, false);
              next= (Button) layout.findViewById(R.id.save);
              next.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
                     //need to change to next fragment
            }
              }
         return layout;
     }
  
     @Override
     public void onSaveInstanceState(Bundle outState) {
         super.onSaveInstanceState(outState);
       //  outState.putString(KEY_CONTENT, mContent);
     }
  }
  </code></pre>
  
  <p>Please help to fix my issue.</p>