I want to get the current position of the visible view of my PagerAdapter
I didn't see an obvious function like getPosition()
and I want one.
I want to add an object into its arraylist at that position, but I need to know it first
I want to get the current position of the visible view of my PagerAdapter
I didn't see an obvious function like getPosition()
and I want one.
I want to add an object into its arraylist at that position, but I need to know it first
https://github.com/Shereef/ViewPagerPlusExpandableList/blob/master/src/net/shereef/vewpagerplusexpandablelistexample/ViewPagerPlusExpandableListActivity.java#L204
if i write after that line
it will show in the logcat the current item page while the oncreate is being run which is always 0
noteice i have used the object for the viewpager it self not the adapter.
Here's an updated solution that I used myself. Since
setOnPageChangeListener
is now deprecated you must useaddOnPageChangeListener
.The implementation above displays the correct index in my
TextView
so that positions0
and the last item in the listcurrentInventory.size()
display correctly. Hope this helps someone looking for an updated solution.You would use:
I had this problem and could not get the
getCurrentItem()
methode.I ended up getting the position from the
ViewPager
and not from thePageAdapter
. TheonPageSelected(int currentPage)
methode is getting the currently displayed page.Doing it in the
PageAdaper
didn't work for me as I want to preload images that are not visible. The position that is passedinstantiateItem(View collection, int position)
of the PageAdapter` is the position of the next item initialized. This has nothing to do with the item that is displayed.