1

I have MotionLayout with Carousel. I want to run some code, when user swipe and move to next slide.

To simplity - I have three slides, SLIDE 1, SLIDE 2, SLIDE3. I need to run some code (change other UI elements, make a toast, ...) when current item is changed. Is this possible?

I tried following:

((MotionLayout)v).setTransitionListener(new MotionLayout.TransitionListener() {
        @Override
        public void onTransitionStarted(MotionLayout motionLayout, int i, int i1) {}

        @Override
        public void onTransitionChange(MotionLayout motionLayout, int i, int i1, float v) {}

        @Override
        public void onTransitionCompleted(MotionLayout motionLayout, int i) {}

        @Override
        public void onTransitionTrigger(MotionLayout motionLayout, int i, boolean b, float v) {}
    });

But in onTransitionCompleted, I can find current transition only (if user swiped forward or backward, not the current item).

Complete code is not necessary, I used first example of the official experiments repo. Thank you for your help.

Tom11
  • 2,419
  • 8
  • 30
  • 56

1 Answers1

0

OnTransitionCompleted has the current state/constraintSet passed as an argument. Not sure what you are asking

void onTransitionCompleted(MotionLayout motionLayout, int currentId);

hoford
  • 4,918
  • 2
  • 19
  • 19
  • `currentId` returns id of `Transition`, not the actual view. When I move from 1st to 2nd, `currentId` is the same as when I move from 2nd to 3rd. – Tom11 Mar 05 '21 at 07:50