title: Class that implements OnPageChangeListener
body: <p>My application uses a connected bluetooth device that sends events to it, so when I receive an event from the BLE device i have to do something. Also i have created an inner class that implements OnPageChangeListener and I also use a class for a sliding tabs. My aim is to "move forward" through the tabs when I receive an event. for example if I am staying in the tab 1, I want to pass to the tab 2 and so on. </p>
  
  <p>How can i do that using my class? my doubt is: what method do I have to call for change the tab? </p>
  
  <p>This is the inner class that implements OnPageChangeListener</p>
  
  <pre><code>    private class InternalViewPagerListener implements ViewPager.OnPageChangeListener {
      private int mScrollState;
  
      @Override
      public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
          int tabStripChildCount = mTabStrip.getChildCount();
          if ((tabStripChildCount == 0) || (position &lt; 0) || (position &gt;= tabStripChildCount)) {
              return;
          }
  
          mTabStrip.onViewPagerPageChanged(position, positionOffset);
  
          View selectedTitle = mTabStrip.getChildAt(position);
          int extraOffset = (selectedTitle != null)
                  ? (int) (positionOffset * selectedTitle.getWidth())
                  : 0;
          scrollToTab(position, extraOffset);
  
          if (mViewPagerPageChangeListener != null) {
              mViewPagerPageChangeListener.onPageScrolled(position, positionOffset,
                      positionOffsetPixels);
          }
      }
  
      @Override
      public void onPageScrollStateChanged(int state) {
          mScrollState = state;
  
          if (mViewPagerPageChangeListener != null) {
              mViewPagerPageChangeListener.onPageScrollStateChanged(state);
          }
      }
  
      @Override
      public void onPageSelected(int position) {
          if (mScrollState == ViewPager.SCROLL_STATE_IDLE) {
              mTabStrip.onViewPagerPageChanged(position, 0f);
              scrollToTab(position, 0);
          }
  
          if (mViewPagerPageChangeListener != null) {
              mViewPagerPageChangeListener.onPageSelected(position);
          }
      }
  
  }
  
  private class TabClickListener implements View.OnClickListener {
      @Override
      public void onClick(View v) {
          for (int i = 0; i &lt; mTabStrip.getChildCount(); i++) {
              if (v == mTabStrip.getChildAt(i)) {
                  mViewPager.setCurrentItem(i);
                  return;
              }
          }
      }
  }
  </code></pre>
  
  <p>i also have this method:</p>
  
  <pre><code>    public void scrollToTab(int tabIndex, int positionOffset) {
      final int tabStripChildCount = mTabStrip.getChildCount();
      if (tabStripChildCount == 0 || tabIndex &lt; 0 || tabIndex &gt;= tabStripChildCount) {
          return;
      }
  
      View selectedChild = mTabStrip.getChildAt(tabIndex);
      if (selectedChild != null) {
          int targetScrollX = selectedChild.getLeft() + positionOffset;
  
          if (tabIndex &gt; 0 || positionOffset &gt; 0) {
              // If we're not at the first child and are mid-scroll, make sure we obey the offset
              targetScrollX -= mTitleOffset;
          }
  
          scrollTo(targetScrollX, 0);
      }
  }
  </code></pre>