Explanation:
Suppose, I have multiple categories which come from my REST. I don\'t know how many categories it\'s mat be 5,7 or sometimes 2 etc. I want
if you want to dynamic tablayout and viewpager you can use this below code for a kotlin;
for (i in 0 until tabLayout.size) {
tabLayout.addTab(tabLayout.newTab().setText(tablayoutNameHere))
}
This area if you want non scrollable you can handle use it;
var tabLayoutConfig = Runnable {
if (tabLayoutPrivilege.width < resources.displayMetrics.widthPixels) {
tabLayoutPrivilege.tabMode = TabLayout.MODE_FIXED
val mParams = tabLayoutPrivilege.layoutParams
mParams.width = ViewGroup.LayoutParams.MATCH_PARENT
tabLayoutPrivilege.layoutParams = mParams
} else {
tabLayoutPrivilege.tabMode = TabLayout.MODE_SCROLLABLE
}
}
tabLayoutPrivilege.post(tabLayoutConfig)
val dynamicPrivilegeFragmentAdapter = DynamicPrivilegeFragmentAdapter(supportFragmentManager, tabCount,yourListHere)
vpPrivilege.adapter = dynamicPrivilegeFragmentAdapter