title: RecyclerView with GridLayoutManager in ViewPAger2 shows nothing in first 3 page
body: <p>I want to create a custom calendarView with ViewPager2 and RecyclerView . When I run the app its showing nothing in 3 first page! But when I scroll it other pages are fine ! This problem happening in android 7.0.0 and below and for android 7.1.1 and above is ok and works good. I created a custom calendar before in same way but now its not working !</p>
  <p>Adapter for ViewPager :</p>
  <pre><code>public class SmartCalendarViewAdapter extends FragmentStateAdapter {
  
      public SmartCalendarViewAdapter(@NonNull FragmentActivity fragmentActivity) {
          super(fragmentActivity);
      }
  
      public SmartCalendarViewAdapter(@NonNull Fragment fragment) {
          super(fragment);
      }
  
      @NonNull
      @Override
      public Fragment createFragment(int pos) {
          return SmartCalendarFragment.getInstance(pos);
      }
  
      @Override
      public int getItemCount() {
          return Integer.MAX_VALUE;
      }
  }
  </code></pre>
  <p>Calendar Fragment :</p>
  <pre><code>    public class SmartCalendarFragment extends Fragment {
  
      private RecyclerView mCalendarRecyclerView;
      private TextView txtPos;
      private int mPosition;
  
  
      public static SmartCalendarFragment getInstance(int position) {
          SmartCalendarFragment smartCalendarFragment = new SmartCalendarFragment();
          Bundle bundle = new Bundle();
          bundle.putInt(&quot;mPosition&quot;, position);
          smartCalendarFragment.setArguments(bundle);
          return smartCalendarFragment;
      }
  
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          Bundle bundle = getArguments();
          if (bundle != null) {
              mPosition = bundle.getInt(&quot;mPosition&quot;);
          }
      }
  
  
      @Nullable
      @Override
      public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
          return inflater.inflate(R.layout.smart_calendar_fragment_layout, container, false);
      }
  
      @Override
      public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
          super.onViewCreated(view, savedInstanceState);
  
          findViews(view);
          ArrayList&lt;Integer&gt; models = new ArrayList&lt;&gt;();
          for (int i = 1; i &lt;= 42; i++) {
              models.add(i);
          }
          mCalendarRecyclerView.setLayoutManager(new GridLayoutManager(getContext(), 7));
          CalendarCellAdapter adapter = new CalendarCellAdapter(models);
          mCalendarRecyclerView.setAdapter(adapter);
          txtPos.setText(String.valueOf(mPosition));
      }
  
      private void findViews(View view) {
          mCalendarRecyclerView = view.findViewById(R.id.smart_calendar_recyclerView);
          txtPos = view.findViewById(R.id.txtPos);
      }
  
  }
  </code></pre>
  <p>Inner RecyclerView Adapter :</p>
  <pre><code>public class CalendarCellAdapter extends RecyclerView.Adapter&lt;CalendarCellAdapter.CellViewHolder&gt; {
      private List&lt;Integer&gt; mSmartCalendarCellModels;
  
      public CalendarCellAdapter(List&lt;Integer&gt; smartCalendarCellModels) {
          mSmartCalendarCellModels = smartCalendarCellModels;
      }
  
      @NonNull
      @Override
      public CellViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) {
          View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.item_attendance_calendar_cell_layout,parent,false);
          return new CellViewHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull CellViewHolder cellViewHolder, int i) {
          cellViewHolder.bindView(mSmartCalendarCellModels.get(i));
      }
  
      @Override
      public int getItemCount() {
          return mSmartCalendarCellModels.size();
      }
  
      class CellViewHolder extends RecyclerView.ViewHolder {
          TextView mTextView;
          public CellViewHolder(@NonNull View itemView) {
              super(itemView);
              mTextView=itemView.findViewById(R.id.item_attendance_cell_txtDate);
          }
          void bindView(Integer model){
              mTextView.setText(String.valueOf(model));
          }
      }
  }
  </code></pre>
  <p>MainActivity :</p>
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      ViewPager2 mViewPager2;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          mViewPager2=findViewById(R.id.viewPager2);
          SmartCalendarViewAdapter adapter=new SmartCalendarViewAdapter(this);
          mViewPager2.setOffscreenPageLimit(1);
          mViewPager2.setAdapter(adapter);
          mViewPager2.setCurrentItem(Integer.MAX_VALUE/2,false);
      }
  }
  </code></pre>
  <p>Fragment layout file :</p>
  <pre><code>&lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:id=&quot;@+id/smart_calendar_fragment_root&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:layoutDirection=&quot;rtl&quot;
      android:orientation=&quot;vertical&quot;&gt;
  
      &lt;TextView
          android:id=&quot;@+id/txtPos&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_marginBottom=&quot;8dp&quot; /&gt;
  
      &lt;androidx.recyclerview.widget.RecyclerView
          android:id=&quot;@+id/smart_calendar_recyclerView&quot;
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:overScrollMode=&quot;never&quot; /&gt;
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <p>Cell Layout file :</p>
  <pre><code>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;wrap_content&quot;
      android:id=&quot;@+id/item_attendance_cell_root&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;&gt;
      &lt;TextView
          android:id=&quot;@+id/item_attendance_cell_txtDate&quot;
          android:layout_width=&quot;0dp&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:gravity=&quot;center&quot;
          app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
          app:layout_constraintDimensionRatio=&quot;w,1:1&quot;
          app:layout_constraintEnd_toEndOf=&quot;parent&quot;
          app:layout_constraintStart_toStartOf=&quot;parent&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          android:padding=&quot;4dp&quot;
          android:layout_marginTop=&quot;4dp&quot;
          android:layout_marginBottom=&quot;4dp&quot;
          tools:text=&quot;1&quot; /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  <p>MainActivity Layout file :</p>
  <pre><code>&lt;androidx.constraintlayout.widget.ConstraintLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
  
      &lt;androidx.viewpager2.widget.ViewPager2
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;
          android:id=&quot;@+id/viewPager2&quot;
          android:background=&quot;#ADABF3&quot;
          app:layout_constraintTop_toTopOf=&quot;parent&quot;
          /&gt;
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>