title: Go to next page in ViewPager
body: <p>I have a <code>ViewPager</code> in my MainActivity. Every page in it is a Fragment. So, everytime I swipe right or left, a new instance of the fragment is created and the fragment view is updated accordingly.</p>
  
  <p>I also have two buttons: <code>LEFT</code> and <code>RIGHT</code> for navigation. These buttons are <strong>inside the Fragment</strong>,  not in the Activity. A user can either swipe or alternatively press the relevant button to navigate between the pages.</p>
  
  <p>Here's the problem: Since I'm changing the views through my MainActivity, how do I detect the <code>onClick</code> events of those buttons in the Activity in order to update the fragment?</p>
  
  <p>Here's the <code>PagerAdapter</code> class (Removed all the irrelevant code from everywhere):</p>
  
  <pre><code>public class SectionsPagerAdapter extends FragmentPagerAdapter {
  
      public SectionsPagerAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public Fragment getItem(int position) {
  
          // logic part for the views.
  
          return PlaceholderFragment.newInstance(sectionNumber, questionStatus, questionOrder, showNext, showPrevious);
      }
  </code></pre>
  
  <p>And here's the <code>PlaceHolderFragment</code> class:</p>
  
  <pre><code>public class PlaceholderFragment extends Fragment{
  
      //some global variables
  
      public static PlaceholderFragment newInstance(int sectionNumber, int questionStatus, String questionOrder, boolean showNext, boolean showPrevious) {
          PlaceholderFragment fragment = new PlaceholderFragment();
  
          //setting up the arguments
          fragment.setArguments(args);
          return fragment;
      }
  
      public PlaceholderFragment() {
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.explanation_fragment, container, false);
  
          //code for filling up all the views
  
          RightButton.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  //can I do something here?
              }
          });
  
          return rootView;
      }
  }
  </code></pre>
  
  <p><strong>MORE INFO:</strong>
  I have to keep the navigation buttons in the fragment itself and not in the activity.</p>