Confusion over the “position” in the instantiateItem function in the PagerAdapter class (android)

I am currently viewing a horizontal paging tutorial: http://mobile.tutsplus.com/tutorials/android/android-user-interface-design-horizontal-view-paging/

For testing purposes, I added the following line as the first line in the instantiateItem (...) function:

Log.d("SimpleViewPagerActivity", "Position " + position); 

(The following is misleading, so it would be better if you try the example yourself to find out what I'm talking about in the next paragraph): In this example, there are 5 ViewPager positions (which are based on zero), and activity is set to start at the position 2. When I start Activity, the log says that the starting position goes from 1, then 2, and then 3. If I scroll left, the log says that the position is 0. When I swipe left again, there is no log message. From here I scroll to the right, and now the position is 2. I sit again to the right, and the position is 3. I sit at other positions on the right, and I get results that I can not explain.

Can someone explain the variable "position" in instatiateItem () or tell me somewhere where it is being explained? I am in the Android v.6 compatibility pack

+4
source share
1 answer

Inside the instantiateItem element, the position parameter is the position that needs to be rendered. This is NOT the position of the currently focused object that the user will see. The pages to the left and right of the currently displayed view must be pre-displayed in memory so that the animation on these screens is smooth.

+9
source

Source: https://habr.com/ru/post/1395848/


All Articles