Android-Image-Slider icon indicating copy to clipboard operation
Android-Image-Slider copied to clipboard

Issues when using the slider in a RecyclerView

Open gnuyork opened this issue 6 years ago • 3 comments

I've got two issues by using the slider nested in a recycler view:

  1. There are a lot of IllegalStateExceptions when I scroll vertically through the RecyclerView, coming from the unRegisterSetObserver() method in PageIndicatorView, complaining that the app tries to remove an observer that has not been added before. (Seems to be a problem caused by the RecyclerView that removes and recreates the slider views while scrolling).
  2. In some (not all) of the slider views in my recycler view I got a strange bug: When I swipe to the second image in the slider the first time, it automatically snaps back to the first one. (This "back-swipe" is then not connected to an onTouch event.)

Has anyone an idea how to fix this (esp. the second problem)?

gnuyork avatar Nov 03 '19 18:11 gnuyork

I fixed the second problem myself by adding the following code to the setSliderAdapter() method in the SliderView:

if (mSliderPager!=null && mCircularSliderHandle!=null){ mSliderPager.removeOnPageChangeListener(mCircularSliderHandle); } mCircularSliderHandle = new CircularSliderHandle(mSliderPager); mSliderPager.addOnPageChangeListener(mCircularSliderHandle);

The reason for the bug is that the RecyclerView doesn't create a new Slider for every entry but reuses the existing ones while scrolling to new elements and just updates their views. So the mCircularSliderHandle object isn't recreated every time, but used for multiple entries which makes the onPageScrollStateChanged() method in the CircularSliderHandle class executing mSliderPager.setCurrentItem(0); sometimes, which produces the behavior mentioned above.

Maybe you could add the lines above to the next release to fix it for other people that also use multiple Sliders in a RecyclerView.

gnuyork avatar Nov 06 '19 15:11 gnuyork

@gnuyork could you please commit your fix? This is still an open bug

panagiac avatar Jan 07 '20 15:01 panagiac

It seems that Version 1.3.5 fixed this issues. At least for me it did, but updating from 1.3.2 it was a breaking change to me as adapter handling seems to be changed

Hatzen avatar May 27 '20 18:05 Hatzen