Refreshing fragments from viewpager 2

Viewed 172

I'm facing an issue refreshing my fragments in viewpager 2 which are host by an activity , in the old viewpager i used to make it work by overriding getItemPosition and return POSITION_NONE and set NotifyDataSetChanged() on the viewpager and it works fine but with viewpager 2 doing the same thing , i didn't get it to work because i guess they took off getItemPosition from viewpager 2 , if any one can guide to solve this problem , i would deeply appreciate it guys , thank you

  • This is my adapter class
class ViewPagerAdapter(fragmentActivity: FragmentActivity) : FragmentStateAdapter(fragmentActivity) {
    private val TABS = 2
    override fun getItemCount(): Int {
        return TABS
    }

    override fun createFragment(position: Int): Fragment {
        return if(position == 0)
            AllNewsFragment()
        else TopHeadlinesFragment()
    }
}
  • This is how i m refreshing the fragments
  MainActivityBinding.mainViewPager.adapter!!.notifyDataSetChanged()

PS: if anything else needed to be shown , i will do it , thank you in advance .

0 Answers
Related