title: TabLayoutOnPageChangeListener onTabReselected called when just switch tab
body: <p>I set up <code>ViewPager</code> with <code>TabLayout</code> like this:</p>
  
  
  
  <pre class="lang-java prettyprint-override"><code>tabLayoutOnPageChangeListener = new TabLayout.TabLayoutOnPageChangeListener(tabLayout);
  
  mViewPager.addOnPageChangeListener(tabLayoutOnPageChangeListener);
  
  tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
      @Override
      public void onTabSelected(TabLayout.Tab tab) {
          mViewPager.setCurrentItem(tab.getPosition());
      }
  
      @Override
      public void onTabUnselected(TabLayout.Tab tab) {
  
      }
  
      @Override
      public void onTabReselected(TabLayout.Tab tab) {
          doSomething();
      }
  });
  </code></pre>
  
  <p>so when I swipe <code>ViewPager</code>, <code>TabLayout</code> will update its indicator and selected tab; and when a tab is selected, <code>ViewPager</code> will change to proper page.</p>
  
  <p>But this causes <code>onTabReselected</code> to be called even if I do not reselect tab, because after <code>onTabSelected</code>, <code>mViewPager.setCurrentItem()</code> will trigger tab selecting again (via <code>tabLayoutOnPageChangeListener</code>). I have to do this:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  public void onTabSelected(TabLayout.Tab tab) {
      mViewPager.removeOnPageChangeListener(tabLayoutOnPageChangeListener);
      mViewPager.setCurrentItem(tab.getPosition());
      mViewPager.addOnPageChangeListener(tabLayoutOnPageChangeListener);
  }
  </code></pre>
  
  <p>to temporary remove listener when <code>setCurrentItem()</code> is called.</p>
  
  <p>Is there any "more right" way to make <code>ViewPager</code> work with <code>TabLayout</code>? I'm using latest v23.0.1 design support library.</p>