yarolegovich/DiscreteScrollView

InfiniteScroll and scrollToPosition

pawelLaz opened this issue · 1 comments

Hello, thanks for this library. I have error when trying to call scrollToPosition or smoothScrollToPosition at Infinite adapter.

To reproduce error change line 41 in WeatherActivity (sample app)
cityPicker.setAdapter(new ForecastAdapter(forecasts));
to this:
cityPicker.setAdapter(InfiniteScrollAdapter.wrap(new ForecastAdapter(forecasts)));

error:

java.lang.IndexOutOfBoundsException: Invalid index 1073741828, size is 6
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.Arrays$ArrayList.get(Arrays.java:66)
at com.yarolegovich.discretescrollview.sample.weather.WeatherActivity.onCurrentItemChanged(WeatherActivity.java:61)

Do you have some solution for this problem?

Edit:
I also trying to use:

InfiniteScrollAdapter adapter = InfiniteScrollAdapter.wrap(new ForecastAdapter(forecasts));
int adapterPosition = adapter.getClosestPosition(3);
cityPicker.smoothScrollToPosition(adapterPosition);

But the result is the same error.
Why adapter position is e.g. 1073741826?

It's in the docs how to translate to a real position.
https://github.com/yarolegovich/DiscreteScrollView#infinite-scroll