I'm currently going through a Horizontal View 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 confusing so it would be better if you try out the example yourself to see what I'm talking about it in the following paragraph): In this example, there are 5 ViewPager positions (which are zero-based) and the Activity is set to start on position 2. When I start the Activity, the Log says that the initial position goes from 1 then 2 and then 3. If I swipe to the left, the log says the position is 0. When I swipe to the left again, there is no log message. From here, I swipe to the right and now the position is 2. I swipe to the right again and the position is 3. I swipe to the other positions on the right and I get results that I cannot explain.
Can someone explain the 'position' variable in instatiateItem() or point me to somewhere where it's explained? I am currently on the Android Compatibility package v.6
Inside of instantiateItem, the position parameter is the position that is in need of rendering. It is NOT the position of the currently focused item that the user would see. The pages to the left and right of the currently displayed view need to be pre rendered in memory so that the animations to those screens will be smooth.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With