title: Cardview with viewpager inside recyclerview item
body: <p>I have tried a lot to implement a CardView which inside has a ViewPager (with fragments) and a TabLayout but RecyclerView shows only the first item and not the others. </p>
  
  <p><a href="https://i.stack.imgur.com/YdKAll.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YdKAll.png" alt="Screenshot"></a></p>
  
  <p>Here is my <code>ViewPagerAdapter</code>:</p>
  
  <pre><code>public class ViewPagerAdapter extends FragmentStatePagerAdapter {
  
      int tabCount;
  
      public ViewPagerAdapter(FragmentManager fm, int tabCount) {
          super(fm);
          this.tabCount= tabCount;
      }
  
  
      @Override
      public Fragment getItem(int position) {
          switch (position) {
              case 0:
                  Tab1 tab1 = new Tab1();
                  return tab1;
              case 1:
                  Tab2 tab2 = new Tab2();
                  return tab2;
              default:
                  return null;
          }
      }
  
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          return super.instantiateItem(container, position);
      }
  
      @Override
      public int getItemPosition(Object object) {
          return POSITION_NONE;
      }
  
      @Override
      public int getCount() {
          return tabCount;
      }
  }
  </code></pre>
  
  <p>Here is my <code>TimeSheetAdapter</code>:</p>
  
  <pre><code>public class TimeSheetAdapter extends RecyclerView.Adapter&lt;TimeSheetAdapter.ViewHolder&gt; {
  
      Context context;
      ArrayList&lt;TimeSheet&gt; timeSheetArrayList;
  
      public TimeSheetAdapter(Context context, ArrayList&lt;TimeSheet&gt; timeSheetArrayList) {
          this.context = context;
          this.timeSheetArrayList = timeSheetArrayList;
      }
  
      public class ViewHolder extends RecyclerView.ViewHolder {
          TabLayout tabLayout;
          ViewPager viewPager;
          ViewPagerAdapter viewPagerAdapter;
  
          public ViewHolder(View itemView) {
              super(itemView);
  
              tabLayout = (TabLayout) itemView.findViewById(R.id.tabLayout);
              viewPager = (ViewPager) itemView.findViewById(R.id.pager);
  
              tabLayout.addTab(tabLayout.newTab().setText("Tab1"));
              tabLayout.addTab(tabLayout.newTab().setText("Tab2"));
              tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
              tabLayout.setupWithViewPager(viewPager);
  
              viewPager.setOffscreenPageLimit(2);
              tabLayout.setupWithViewPager(viewPager);
  
          }
      }
  
      public TimeSheetAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View viewHolder = LayoutInflater.from(parent.getContext()).inflate(R.layout.time_sheet_row, parent, false);
  
          return new TimeSheetAdapter.ViewHolder(viewHolder);
      }
  
      @Override
      public void onBindViewHolder(TimeSheetAdapter.ViewHolder holder, int position) {
  
          ViewPagerAdapter adapter = new ViewPagerAdapter(((AppCompatActivity) context).getSupportFragmentManager(), holder.tabLayout.getTabCount());
          holder. viewPager.setAdapter(adapter);
  
          if (holder.tabLayout != null) {
              for (int i = 0; i &lt; holder.tabLayout.getTabCount(); i++) {
                  TabLayout.Tab tab = holder.tabLayout.getTabAt(i);
                  if (tab != null)
                      tab.setText("Tab " + Integer.toString(i + 1));
              }
          }
          holder.viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(holder.tabLayout));
      }
  
      @Override
      public int getItemCount() {
          return timeSheetArrayList.size();
      }
  }
  </code></pre>