Last active
October 10, 2018 06:30
-
-
Save mostafa-hz/dc006f55ed2d31acfb2114852f26294b 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
class FragmentPagerAdapterSample(manager: FragmentManager) : FragmentPagerAdapter(manager) { | |
private val data = ArrayList<Any>() | |
fun setData(data: List<Any>) { | |
this.data.clear() | |
this.data.addAll(data) | |
notifyDataSetChanged() | |
} | |
override fun getItem(position: Int) = when (data[position]) { | |
is Question -> QuestionFragment.newInstance(data[position] as Question) | |
is Answer -> AnswerFragment.newInstance(data[position] as Answer) | |
else -> null | |
} | |
override fun getCount() = data.size | |
override fun getPageTitle(position: Int) = data[position].toString() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment