46.7 Creating the Fragment State Adapter
This example will use the ViewPager2 approach to handling the fragments assigned to the TabLayout tabs. With the ViewPager2 instance added to the layout resource file, a new class which subclasses FragmentStateAdapter needs to be added to the project to manage the fragments that will be displayed when the tab items are selected by the user.
Add a new class to the project by right-clicking on the com.ebookfrenzy.tablayoutdemo entry in the Project tool window and selecting the New -> Java Class menu option. In the new class dialog, enter TabStateAdapter into the Name: field and click OK.
Edit the TabStateAdapter.java file so that it reads as follows:
package com.ebookfrenzy.tablayoutdemo;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.viewpager2.adapter.FragmentStateAdapter;
public class TabStateAdapter extends FragmentStateAdapter {
...