1

I used the android.animation.AnimatorListenerAdapter class in my code to listen to animations. Example :

downView.animate().translationX(-mViewWidth).setDuration(mAnimationTime).
setListener(new AnimatorListenerAdapter() {                     
@Override
    public void onAnimationStart(
    Animator animation) {
    boolean real_dismiss = true;
    performDismiss(
//some code
)
    }

I used the backward compatibility lib by nineoldandroids, the animations work fine, but i am getting the following error, that does not let me run my code, at my listener:

The method setListener(Animator.AnimatorListener) in the type ViewPropertyAnimator is not applicable for the arguments (new AnimatorListenerAdapter(){})

The code was working fine when I was using the API level 11. My old import statements:

//import android.animation.Animator;
//import android.animation.AnimatorListenerAdapter;
//import android.animation.ValueAnimator;

My new import statement :

import com.nineoldandroids.animation.*;
import com.nineoldandroids.*;
newbie
  • 1,049
  • 5
  • 15
  • 29

1 Answers1

2

I just encountered the same problem and found Jake Wharton's implementation of SwipeDismissListener:

On Line 156, Jake is using com.nineoldandroids.view.ViewPropertyAnimator.animate(View arg0) to perform the same function.

Therefore, all you need is to change your code to something like this:

animate(downView)
.translationX(-mViewWidth)
.setDuration(mAnimationTime)
.setListener(new AnimatorListenerAdapter() {  

@Override
    public void onAnimationStart(Animator animation) {
    boolean real_dismiss = true;
    performDismiss(//some code)
}

And there shouldn't be any error.

dumbfingers
  • 7,001
  • 5
  • 54
  • 80
  • any idea why onAnimationStart(Animator animation) doesn't get called even though the animation is effectuated ? – Lucas Apr 08 '14 at 12:30
  • @Lucas that answer was long time ago, could u be more specific about the issue? thx – dumbfingers Apr 08 '14 at 12:36
  • it worked when I used public void onAnimationStart(com.nineoldandroids.animation.Animator animation). There was maybe a confusion of which library to use – Lucas Apr 08 '14 at 14:48
  • Just don't forget to add `import static com.nineoldandroids.view.ViewPropertyAnimator.animate;`. – Gábor Dec 10 '14 at 16:46