0

I'm newbie Android developer. I'm having problems writing a method that is designed to pause the application until the end of an animation.

This is my code:

public void CorrectAnimation() {
        Log.d("CorrectAnim", "Pass" );
        final Button answer_1 = (Button) findViewById(R.id.answer_1);
        final Button answer_2 = (Button) findViewById(R.id.answer_2);
        final Button answer_3 = (Button) findViewById(R.id.answer_3);
        final Button answer_4 = (Button) findViewById(R.id.answer_4);

        if (iAnswer_1 == 1) {

            answer_1.setBackgroundResource(R.drawable.button_correctly);
            AnimationDrawable animAnswer_1 = (AnimationDrawable) answer_1.getBackground();
            animAnswer_1.start();
            checkIfAnimationDone(animAnswer_1);

        }
        ...
    }


private void checkIfAnimationDone(AnimationDrawable anim){
        Log.d("Check", "Pass" );
        final AnimationDrawable a = anim;
        int timeBetweenChecks = 2500;
        Handler h = new Handler();
        h.postDelayed(new Runnable(){
            @override
            public void run(){
                Log.d("checkRun", "Pass" );
                if (a.getCurrent() != a.getFrame(a.getNumberOfFrames() - 1)){
                    Log.d("checkRunIf", "Pass" );
                    checkIfAnimationDone(a);
                } else{
                    Toast.makeText(getApplicationContext(), "ANIMATION DONE!", Toast.LENGTH_SHORT).show();
                }
            }
        }, timeBetweenChecks);
    };

The problem is that checkIfAnimationDone() ignores the method Run().

RESOLVE: I forget add @override above "public run()". Code now is working :)

1 Answers1

0

check out this question, he is using overrinding the onAnimationFinished() method...

Android AnimationDrawable and knowing when animation ends

Community
  • 1
  • 1
Dave
  • 867
  • 6
  • 11