Last active
July 28, 2019 17:13
-
-
Save addeeandra/07294a6fe62748ab40252a4a99ea2ad8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import androidx.fragment.app.Fragment | |
import androidx.fragment.app.FragmentManager | |
import androidx.fragment.app.FragmentPagerAdapter | |
import androidx.viewpager.widget.ViewPager | |
import com.google.android.material.tabs.TabLayout | |
open class AnyFragmentPagerAdapter( | |
fm: FragmentManager, | |
private val mPages: List<AnyPagerableFragment> | |
) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { | |
override fun getItem(position: Int): Fragment { | |
return mPages[position] | |
} | |
override fun getCount(): Int { | |
return mPages.size | |
} | |
override fun getPageTitle(position: Int): CharSequence? { | |
return mPages[position].title | |
} | |
fun setup(viewPager: ViewPager, tabLayout: TabLayout) { | |
viewPager.adapter = this | |
tabLayout.setupWithViewPager(viewPager, true) | |
} | |
abstract class AnyPagerableFragment : Fragment() { | |
abstract val title: String | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment