I have a simple FragmentPagerAdaper
, and I have overriden the getItem
and getCount
methods.
Everything works fine until I change the data.
Even after calling notifyDataSetChanged
, the ViewPager
is showing the old fragment, even tough I am not returning it in getItem
.
Kotlin Code:
private inner class Adapter(fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) {
override fun getItem(position: Int): Fragment {
when (getType(position)) {
Constants.CHAT_TYPE_PARTNER -> {
return TaskChatFragment.newInstance(...)
}
Constants.CHAT_TYPE_SUPPORT -> {
return TaskChatFragment.newInstance(...)
}
}
throw IllegalArgumentException("invalid position " + position)
}
fun getPosition(type: Int) =
if (type == Constants.CHAT_TYPE_SUPPORT && shouldShowPartnerChat()) 1 else 0
override fun getCount(): Int {
var count = 0
if (shouldShowPartnerChat()) count++
if (shouldShowSupportChat()) count++
return count
}
}