How to make the code next after using the animation wait for the animation to complete? Now it starts to run in parallel with the launch of the animation.
Method using animation:
private void moveToHistory() { Animation animation = AnimationUtils.loadAnimation(this, R.anim.move_operation); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { historyField.setText(getNumberField()); historyOperation.setText(operationField.getText().toString()); numberField.setText(" "); operationField.setText(" "); } @Override public void onAnimationRepeat(Animation animation) { } }); numberField.startAnimation(animation); operationField.startAnimation(animation); } Another method with animation:
private void clearCalculation() { Animation animation = AnimationUtils.loadAnimation(MainActivity.this, R.anim.dissolution); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { numberField.setText(" "); operationField.setText(" "); historyField.setText(" "); historyOperation.setText(" "); isPercentCalculation = false; isResult = false; } @Override public void onAnimationRepeat(Animation animation) { } }); numberField.startAnimation(animation); operationField.startAnimation(animation); historyField.startAnimation(animation); historyOperation.startAnimation(animation); } An example of code in which methods with animation can be called:
private void addNumber(String s) { if (isResult || isError()) clearCalculation(); //есть анимация if (!isEmpty(operationField)) moveToHistory(); //есть анимация //вот эта часть начинает выполняться сразу после запуска анимации //не дожидаясь результата работы onAnimationEnd() if (getCountNumbers(numberField) < 11) { if (getNumberField().equals("0")) { String temp = "0." + s; numberField.setText(temp); } else { String temp = getNumberField() + s; numberField.setText(temp); } } } Methods with animation are called in many places of the program. Often, after calling these methods, other code follows, which starts before the animation ends. And I need him to wait, because the onAnimationEnd () blocks execute what needs to be completed before executing further code.
Moving the entire code to the onAnimationEnd () block is not a solution.