Creating Adapter

To have a swipe Tab layout, we need to create an Adapter for ViewPager and add it to the TabLayout. This adapter class renders Fragment to each ViewPager’s page. Our ViewPagerAdapter class extends from FragmentStatePagerAdapter. We need to override three methods getItem(), getCount(), getPageTitle(). The getItem() method requires a Fragment instance for each Tab position. The getCount() method needs the total fragment count. The getPageTitle() method requires page title as String for each Tab position. This method is required for displaying name of the Tab.