Created
July 26, 2020 14:35
-
-
Save rmyhal/54a456599ad919a0b154e30c3a2ea2e1 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 PagerAdapter(private val activity: FragmentActivity) : FragmentStateAdapter(activity) { | |
private val items: ArrayList<PagerItem> = arrayListOf() | |
override fun createFragment(position: Int): Fragment = | |
PagerFragment.newInstance(items[position]) | |
override fun getItemCount() = items.size | |
override fun getItemId(position: Int): Long { | |
return items[position].id.toLong() | |
} | |
override fun containsItem(itemId: Long): Boolean { | |
return items.any { it.id.toLong() == itemId } | |
} | |
fun setItems(newItems: List<PagerItem>) { | |
items.clear() | |
items.addAll(newItems) | |
notifyDataSetChanged() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment