sayyam / carouselview

A simple library to add carousel view in android app.
Apache License 2.0
1.15k stars 260 forks source link

Trigger an event whenever the image changes #121

Open Eleuis opened 4 years ago

Eleuis commented 4 years ago

Is there any way to trigger an event whenever the image changes? I need to update a textview to display information related to what is currently being shown

guilhermegchagas commented 4 years ago

You need to add a page change listener to the carousel view.

carouselView.addOnPageChangeListener(new OnPageChangeListener() {
    public void onPageScrollStateChanged(int state) {}
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
    public void onPageSelected(int position) {
        // Check if this is the page you want.
    }

});

I found this solution in the link below, but i'm using C# in my project, so i don't know if that specific implementation works, but it worked in my project with some adaptations to C#. https://stackoverflow.com/questions/11293300/determine-when-a-viewpager-changes-pages