title: Warning in ViewPager and TabLayout (not updated inline; expected state 3 found 2)
body: <blockquote>
  <p>compile 'com.android.support:support-v4:23.4.0' using this version of support library.</p>
  </blockquote>
  <p><em>Gone through this link but could not found the exact solution</em></p>
  <blockquote>
  <p><a href="https://stackoverflow.com/questions/35810115/tabviewpager-not-updating-instead-shows-weird-warning-expected-state-3-found-2">Tab+ViewPager not updating instead shows weird warning expected state 3 found 2</a></p>
  <p><a href="https://stackoverflow.com/questions/35783098/android-viewpager-loading-incorrect-fragments">Android ViewPager Loading incorrect fragments</a></p>
  </blockquote>
  <p><strong>W/FragmentManager: moveToState: Fragment state for A{7bb406c #3 id=0x7f0d0087} not updated inline; expected state 3 found 2</strong></p>
  <blockquote>
  <p>TabLayout and ViewPager in Activity.</p>
  </blockquote>
  <pre><code>if (tabLayout!=null) {
          tabLayout.addTab(tabLayout.newTab().setText(&quot;A&quot;));
          tabLayout.addTab(tabLayout.newTab().setText(&quot;B&quot;));
          tabLayout.addTab(tabLayout.newTab().setText(&quot;C&quot;));
          tabLayout.addTab(tabLayout.newTab().setText(&quot;D&quot;));
          tabLayout.addTab(tabLayout.newTab().setText(&quot;E&quot;));
          tabLayout.addTab(tabLayout.newTab().setText(&quot;F&quot;));
          tabLayout.addTab(tabLayout.newTab().setText(&quot;G&quot;));
          tabLayout.addTab(tabLayout.newTab().setText(&quot;H&quot;));
      }
  
      adapter=new ViewPagerAdapter(getSupportFragmentManager(),tabLayout.getTabCount());
      mVPCompare.setAdapter(adapter);
  
  
      mVPCompare.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
      tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
          @Override
          public void onTabSelected(TabLayout.Tab tab) {
              mVPCompare.setCurrentItem(tab.getPosition(),true);
          }
  
          @Override
          public void onTabUnselected(TabLayout.Tab tab) {
          }
  
          @Override
          public void onTabReselected(TabLayout.Tab tab) {
  
          }
      });
  
     
  </code></pre>
  <blockquote>
  <p>Adapter Class.</p>
  </blockquote>
  <pre><code>public class ViewPagerAdapter extends FragmentStatePagerAdapter {
  
  
  int pages;
  
  public ViewPagerAdapter(FragmentManager fm,int pages) {
      super(fm);
      this.pages=pages;
  }
  @Override
  public Fragment getItem(int position) {
  
  
  
      Fragment fragment;
  
      switch (position)
      {
          case 0:
              fragment=new A();
              return fragment;
  
          case 1:
              fragment=new B();
              return  fragment;
  
          case 2:
              fragment=new C();
              return fragment;
  
          case 3:
              fragment=new D();
              return fragment;
  
          case 4:
              fragment=new E();
              return fragment;
  
          case 5:
              fragment=new F();
              return fragment;
  
          case 6:
              fragment=new G();
              return fragment;
  
          case 7:
              fragment=new H();
              return fragment;
  
          default:
              return null;
      }
  
  }
  
  @Override
  public int getCount() {
      return pages;
  }
  </code></pre>
  <p>}</p>