Detect change in the carousel programmatically
jesustrejo10 opened this issue · 1 comments
Hello, I have a frame layout, in that frame layout first, I have the carouselView, next I have a LinearLayout. like this.
<Frame>
<CarouselView>
<Linearlayout>
</Frame>
In my linear layout I have the detail of the picture, in my case I'm showing hotels, so in the linear I have the name of the hotel, stars etc, I need to update that information when the image change, but I don't know how to reconoce the event when the image change to update the info. Exists any way to detect that event?
-
I tryed to set the changes on the ImageListener but after pass to the last item (reach the end of the images) the info doesn't change anymore.
-
I readed about the custom view, using View Listener but i'm not sure than how can I implement that.
Thank you for your answer.
Hi,
The carousel is based on a ViewPager, so you can use the addOnPageChangeListener and override the "onPageSelected" method to update your layout. Here's an example wrote in Kotlin
carousel.addOnPageChangeListener(object: ViewPager.OnPageChangeListener {
override fun onPageScrollStateChanged(state: Int) {}
override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {}
override fun onPageSelected(position: Int) {
//Update your layout here
}
})
Happy coding ;)