ViewPager
ViewPager¶
When using ViewPager
, use DevViewPagerAdapter
for fragment configuration:
val adapter = DevViewPagerAdapter(
fm = supportFragmentManager, // Fragment Manager where you inflate ViewPager
listFragment = arrayListOf(AllUserFragment(), FavoriteUserFragment()), // list of DevFragment
listTitle = arrayListOf("All", "Favorite") // List of title for the fragment, nullable
)
ViewPager2¶
When using ViewPager2
, just call method setup
to configure it:
binding.vpMain.setup {
// REQUIRED
withActivity(this) // (1)
withFragment(this) // (2)
withListFragment(listOf(fragmentA, fragmentB)) // (3)
// Optional
bindWithTabLayout(binding.tabLayoutMain) { // (4)
withListTitles(listOf("title A", "title B")) // (5)
withListIcon(listOf(getDrawableResource(R.drawable.ic_list), getDrawableResource(R.drawable.ic_star))) // (6)
}
}
- When
ViewPager
inflated insideActivity
- When
ViewPager
inflated insideFragment
- Define list
Fragment
- Bind
ViewPager2
withTabLayout
- Add Title to
TabLayout
- Add icon to the tab