What is the correct way to load data in ViewPager

make a linked page with tablayout and ViewPager

I judge the position in the instantiateItem of the ViewPager adapter to load the network data

but I don"t know why data loaded with position 0 will end up on position 1

I checked the information and said that I wanted to update the data in the addOnPageChangeListener of ViewPager, but I was a little confused about how to update it in onPageSelected

ask for advice on the correct way to load data. Thank you

Mar.14,2021

you post the code


"but I don't know why the data loaded with position 0 will be on position 1". Just subtract 1 when you get the data, like this:
data.get (position-1)


FragmentPagerAdapter / FragmentStatePagerAdapter learn about
Menu