53.7 Creating the Pager Adapter
This example will use the ViewPager2 approach to handling the fragments assigned to the TabLayout tabs. With the ViewPager2 added to the layout resource file, a new class which subclasses FragmentPagerAdapter 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 -> Kotlin File/Class menu option. In the new class dialog, enter TabPagerAdapter into the Name: field, select the Class item in the list and press the keyboard Return key.
Edit the TabPagerAdapter.kt file so that it reads as follows:
package com.ebookfrenzy.tablayoutdemo
import androidx.fragment.app.*
import androidx.viewpager2.adapter.FragmentStateAdapter
class TabPagerAdapterTabPagerAdapter(fa: FragmentActivity,
&...