title: ViewPager Issue while Scrolling
body: <p>When I am scrolling the viewpager from tab0 to tab1 then tab1 is shown correctly but it hitting the tab2 webservice. similiary when tab2 is shown then it's hitting tab3 webservice.</p>
  
  <pre><code>public class OrderDetailsTab extends Fragment {
      View view;
      ViewPager viewPager;
      TabLayout tabLayout;
  
      public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          view = inflater.inflate(R.layout.tab_layout, container, false);
  
          tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
          viewPager = (ViewPager) view.findViewById(R.id.pager);
  
          tabLayout.addTab(tabLayout.newTab().setText("STATUS"));
          tabLayout.addTab(tabLayout.newTab().setText("TRUCKS"));
          tabLayout.addTab(tabLayout.newTab().setText("CHARGES"));
          tabLayout.addTab(tabLayout.newTab().setText("QUOTES"));
          tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
  
          viewPager.setAdapter(new MyPagerAdapter(getActivity().getSupportFragmentManager()));
          MyPagerAdapter myPagerAdapter=new MyPagerAdapter(getActivity().getSupportFragmentManager());
          viewPager.setAdapter(myPagerAdapter);
          myPagerAdapter.notifyDataSetChanged();
          tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
              @Override
              public void onTabSelected(TabLayout.Tab tab) {
                  viewPager.setCurrentItem(tab.getPosition());
              }
  
              @Override
              public void onTabUnselected(TabLayout.Tab tab) {
  
              }
  
              @Override
              public void onTabReselected(TabLayout.Tab tab) {
  
              }
          });
  
          myPagerAdapter.getRegisteredFragment(viewPager.getCurrentItem());
  
          return view;
  
      }
      public static class MyPagerAdapter extends DetailPagerAdapter{
          private static int NUM_ITEMS = 4;
  
          public MyPagerAdapter(FragmentManager fragmentManager) {
              super(fragmentManager);
          }
  
          @Override
          public Fragment getItem(int position) {
              switch (position) {
                  case 0:
                      return StatusTab.init(0);
                  case 1:
                      return TruckInfoTab.init(1);
                  case 2:
                      return ApprovalTab.init(2);
                  case 3:
                      return QuotesFragment.init(3);
                  default:
                      return null;
              }
          }
  
          @Override
          public int getCount() {
              return NUM_ITEMS;
          }
          @Override
          public CharSequence getPageTitle(int position) {
              return "Page " + position;
          }
      }
  
  
      @Override
      public void onResume() {
          super.onResume();
          ((AppCompatActivity) getActivity()).getSupportActionBar().hide();
  
      }
  
  }
  </code></pre>
  
  <p>Abstract Adapter Class:</p>
  
  <pre><code>public abstract class DetailPagerAdapter extends FragmentPagerAdapter {
  
  
      // Sparse array to keep track of registered fragments in memory
      private SparseArray&lt;Fragment&gt; registeredFragments = new SparseArray&lt;Fragment&gt;();
  
      public DetailPagerAdapter(FragmentManager fragmentManager) {
          super(fragmentManager);
      }
  
      // Register the fragment when the item is instantiated
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          Fragment fragment = (Fragment) super.instantiateItem(container, position);
          registeredFragments.put(position, fragment);
          return fragment;
      }
  
      // Unregister when the item is inactive
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          registeredFragments.remove(position);
          super.destroyItem(container, position, object);
      }
  
      // Returns the fragment for the position (if instantiated)
      public Fragment getRegisteredFragment(int position) {
          Log.e("pos---", "" + position);
          return registeredFragments.get(position);
      }
  }
  </code></pre>