简体   繁体   中英

ViewPager.instantiateItem() position

I am trying to figure out a view´s absolute position, but so far it seems more like a relative position which gets passed, but then again, it also seems at times that it is based on pure randomness?

Look at this output I have from my ViewPager, switching between 5 views forth, back and forth again, I cannot find any pattern in it:

 size: 0, pos: 0 size: 1, pos: 1 size: 2, pos: 2 size: 2, pos: 3 size: 2, pos: 4 size: 2, pos: 2 size: 3, pos: 1 size: 3, pos: 0 size: 2, pos: 2 size: 2, pos: 3 size: 2, pos: 4 

Basically what I am doing is trying to get the respective ListAdapter for each ListView in my ViewPagerAdapter, and then set them accordingly to their respective views (ListAdapter for the first list gets added to the first view eg.) this breaks however since the position given as argument in instantiateItem seems to not really follow any pattern.

So, is there any way to find out what the absolute position of a View in PagerView is?

Ok - I just fixed the problem myself, what I thought was the problem was actually not, I just think I kind of misunderstood how instantiateItem works. What I was trying to do was to get the current ListAdapter from my ViewPager, and I of course then thought I might as well retrive it from ViewPager.getChildAt(), but this of course is not the right procedure, because ViewPager only remembers the current View, and one View forth and back. The right way to do it, is to save the views in a ViewPagerAdapter, and then retrieve the Views from there when you need to reference them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM