Skip to content

Instantly share code, notes, and snippets.

@mostafa-hz
Last active October 10, 2018 06:30
Show Gist options
  • Save mostafa-hz/dc006f55ed2d31acfb2114852f26294b to your computer and use it in GitHub Desktop.
Save mostafa-hz/dc006f55ed2d31acfb2114852f26294b to your computer and use it in GitHub Desktop.
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