ViewPager in Android
Overview Viewpager is a layout manager which allows a user to flip left or right throughout the pages of our application with data. Steps to create a static ViewPager Create an Enum for all the layouts enum class ModelObject( val titleId : Int , val layoutId : Int) { RED (R.string. red , R.layout. red_view ) , BLUE (R.string. blue , R.layout. blue_view ) , GREEN (R.string. green , R.layout. green_view ) ; } Create a class and extend it with PagerAdapter . Apart from implementing the abstract methods isViewFromObject and getCount , you also have to override instantiateItem and destroyItem class CustomPagerAdapter( private val context : Context) : PagerAdapter() { override fun getCount () : Int { return ModelObject.values(). size } override fun isViewFromObject (view : View , `object` : Any) : Boolean { return view == `object` } override fun instantiateItem (container : ViewGroup , position : Int) : Any { ...