antonyt / InfiniteViewPager

Augment Android's ViewPager with wrap-around functionality.
MIT License
695 stars 194 forks source link

Jump to any item using setCurrentItem(3,true); is not working correctly #8

Closed vipinhelloindia closed 10 years ago

vipinhelloindia commented 10 years ago
viewPager.setCurrentItem(viewPager.getCurrentItem() + 1);
aeroechelon commented 10 years ago

Please see pull request #15 for this fix.

DigitalDavo commented 10 years ago

I have this fix, but still get an infinite for(); loop entry on about half of my calls to setCurrentItem();

aeroechelon commented 10 years ago

Infinite for loop on some of your calls to setCurrentItem()? The fix essentially forwards the params of overloaded methodsetCurrenItem(int, boolean) to the original method setCurrenItem(int). Could you post more details of your issue?

@Override
    public void setCurrentItem(int item) {
        // offset the current item to ensure there is space to scroll
        setCurrentItem(item, false);
    }

    @Override
    public void setCurrentItem(int item, boolean smoothScroll) {
        item = getOffsetAmount() + (item % getAdapter().getCount());
        super.setCurrentItem(item, smoothScroll);
    }
DigitalDavo commented 10 years ago

I have 4 fragments. There are links from fragment0 to the 3 other fragments, and then a "BACK" link to fragment0 from the other fragments. It is a bit hit and miss as to whether you will get across or back to the main fragment or not. Half of the time it works and the other half of the time you hit the infinite loop and after 20 seconds you get the system isn't responding wait/ok/report dialogue.

It was reported on stackoverflow that it failed if the transition was from a lower to a higher virtual position number, but I'm not sure it was thas simple.

aeroechelon commented 10 years ago

Do you see the same issue if you use setCurrentItem(int item)?