Another nice solution is not overriding the onTextChanged Method, and having two methods setText: A public one that will trigger the animation, and a private one that will change the value without animating:
private void init(){
actualValue = 0;
animator = new ValueAnimator();
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
setTextInternal(valueAnimator.getAnimatedValue().toString());
actualValue = (Float)valueAnimator.getAnimatedValue();
}
});
animator.setDuration(DURATION);
}
public void setNumber(float newValue){
animator.cancel();
animator.setFloatValues(actualValue, newValue);
animator.start();
}
public void setText(String txt){
try {
float newValue = Float.parseFloat(txt);
setNumber(newValue);
}catch (Exception e){
super.setText(txt);
}
}
private void setTextInternal(String txt){
super.setText(txt);
}