title: Viewpager wrong OnItemClick position
body: <p>My app has a fragment that host a nested viewPager (One fragment added every time)  all views are linked to the same layout.</p>
  
  <p>Each fragment has a fixed button + recylerview that retrieve its data from firebase adapter. </p>
  
  <p>When I click on the button, it show the correct viewPager position. But if I click on the listview item (viewHolder) it show the next pre-loaded position in the viewPager. </p>
  
  <p>here's the viewpager and the pager adapter of the root fragment</p>
  
  <p><strong>Explore.java</strong></p>
  
  <pre><code>@Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View root = inflater.inflate(R.layout.fragment_explore, container, false);
      array = controller.SELECTED_CATEGORIES;
      viewPager = (ViewPager) root.findViewById(R.id.viewPager);
      tabLayout = (TabLayout) root.findViewById(R.id.categories_tablayout);
      tabLayout.setupWithViewPager(viewPager);
      mAdapter = new MyAdapter(getFragmentManager());
      viewPager.setAdapter(mAdapter);
      return root;
  }
  
  public static class MyAdapter extends FragmentStatePagerAdapter {
  
  public MyAdapter(FragmentManager fm) {
          super(fm);
      }
  
      @Override
      public int getCount() {
          return controller.SELECTED_CATEGORIES.length;
      }
  
      @Override
      public Fragment getItem(int position) {
          return CategoriesFragment.newInstance(position);
      }
      @Override
      public CharSequence getPageTitle(final int position) {
          return controller.SELECTED_CATEGORIES[position];
      }
  }
  </code></pre>
  
  <p><strong>CategoriesFragment.java</strong></p>
  
  <pre><code>static CategoriesFragment newInstance(int num) {
      CategoriesFragment f = new CategoriesFragment();
      Bundle args = new Bundle();
      args.putInt("num", num);
      f.setArguments(args);
  
      return f;
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      rootView = inflater.inflate(R.layout.fragment_categories, container, false);
      initialize();
      listCategoriesFeed = (RecyclerView) rootView.findViewById(R.id.listCategoriesFeeds);
      categoriesFeedAdapter = new CategoriesFeedAdapter(CategoriesFeedItem.class, R.layout.categoriesfeed_list_item, CategoriesFeedHolder.class, myref);
      llm = new LinearLayoutManager(rootView.getContext());
      llm.setOrientation(LinearLayoutManager.VERTICAL);
  
      listCategoriesFeed.setLayoutManager(llm);
      listCategoriesFeed.setAdapter(categoriesFeedAdapter);
  
      swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout);
      swipeRefreshLayout.setOnRefreshListener(this);
  
      //Holder itemClickListener
      CategoriesFeedHolder.registerOnItemClickListener(this);
  
      //TextView onclick listener
      View tv = rootView.findViewById(R.id.text);
      ((TextView)tv).setText("Fragment #" + mNum);
      tv.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Log.e("position",mNum + "");
          }
      });
      return rootView;
  }
  
  @Override
  public void onItemClick(View view, int position) {
  super.onItemClick(view, position);
      switch (view.getId()) {
          case R.id.firstId:  
              Log.e("position",mNum+ "");
              break;
          case R.id.secondId:
              secondAction....
              .....
              .....
              .....
              break;
      }
  }
  
  
  private void initialize() {
      controller.showProgressDialog();
      list = controller.getIniCategoriesDetailsList();
      list.clear();
      controller.categoriesDetailsList.put(controller.SELECTED_CATEGORIES[mNum],list);
      reference = FirebaseDatabase.getInstance().getReference("firebase-path/" + controller.SELECTED_CATEGORIES[mNum]);
      myref = reference.orderByChild("order-by").limitToFirst(i);
      myref.addChildEventListener(this);
  }
  </code></pre>
  
  <p><strong>CategoriesFeedHolder.java</strong></p>
  
  <pre><code>private CategoriesFeedItem model;
  private final ImageView mImage;
  
  private static OnItemClickListener onItemClickListener;
  
  public CategoriesFeedHolder(View itemView) {
      super(itemView);
      this.context = itemView.getContext();
  
      mImage = (ImageView) itemView.findViewById(R.id.m_image);
      mImage.setOnClickListener(this);
  }
  
  public static void registerOnItemClickListener(OnItemClickListener onItemClickListener) {
      CategoriesFeedHolder.onItemClickListener = onItemClickListener;
  }
  
  public void setModel(CategoriesFeedItem model) {
      this.model = model;
  }
  
  @Override
  public void onClick(View view) {
      onItemClickListener.onItemClick(view, getAdapterPosition());
  }
  </code></pre>
  
  <p>Does anyone know why this happens? </p>