Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/352.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 暂停应用程序,直到AnimationDrawable完成_Java_Android - Fatal编程技术网

Java 暂停应用程序,直到AnimationDrawable完成

Java 暂停应用程序,直到AnimationDrawable完成,java,android,Java,Android,我是Android开发新手。我在编写一个暂停应用程序直到动画结束的方法时遇到问题 这是我的代码: 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.

我是Android开发新手。我在编写一个暂停应用程序直到动画结束的方法时遇到问题

这是我的代码:

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);
    };
问题是checkIfAnimationDone忽略了方法运行


解决方法:我忘记在公共运行之上添加@override。代码正在运行:

检查这个问题,他正在使用onAnimationFinished方法进行过度编译