0

我有一个 ImageButton (blueCondition) 的 OnTouchListener。当 MotionEvent.ACTION_UP 被激活时,另一个 ImageButton 将 startFlipping()。如果在再次按下 ImageButton (blueCondition) (MotionEvent.ACTION_DOWN) 之前到达 ViewFlipper 的最后一个图像,那么我需要采取一些措施。我的 ImageButton 代码是:

blueCondition = (ImageButton)findViewById(R.id.ImageButton04);
flipper1.startFlipping();


blueCondition.setOnTouchListener(new OnTouchListener(){
    public boolean onTouch(View v, MotionEvent event){
        switch(event.getAction()){


        case MotionEvent.ACTION_DOWN:
            flipper1.stopFlipping();
            flipper1.setDisplayedChild(0);
            blueCondition.setImageResource(R.drawable.blue_print_button300);
            break;
        case MotionEvent.ACTION_UP:
            flipper1.startFlipping();
            blueCondition.setImageResource(R.drawable.blue_circle300);
            break;
        }
        return true;
    }
});//endsetOnTouchListener

从其他问题和答案中,我尝试使用以下代码对我们进行动画处理:

Flipper1.getInAnimation().setAnimationListener(new Animation.AnimationListener() {

    public void onAnimationStart(Animation animation) {}
    public void onAnimationRepeat(Animation animation) {}
    public void onAnimationEnd(Animation animation) {

        int displayedChild = flipper1.getDisplayedChild();
        int childCount = flipper1.getChildCount();

        if (displayedChild == childCount - 1) {
            flipper1.stopFlipping();
        }
    }
});

这似乎可以编译,但在运行时会崩溃。我想我遗漏了一些明显的东西。任何帮助将不胜感激。

下面包括的是logcat:

08-23 21:26:08.282: E/AndroidRuntime(32767): 致命异常: main 08-23 21:26:08.282: E/AndroidRuntime(32767): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com. andytwistertrials_1/com.andytwistertrials_2.MainActivity}: java.lang.NullPointerException 08-23 21:26:08.282: E/AndroidRuntime(32767): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097) 08-23 21: 26:08.282: E/AndroidRuntime(32767): 在 android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在 android.app.ActivityThread.access $600(ActivityThread.java:140) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在 android.os.Handler.dispatchMessage(Handler.java:99) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在 android.os.Looper.loop(Looper.java:137) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在android.app.ActivityThread.main(ActivityThread.java:4895) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在 java.lang.reflect.Method.invokeNative(Native Method) 08-23 21:26 :08.282: E/AndroidRuntime(32767): at java.lang.reflect.Method.invoke(Method.java:511) 08-23 21:26:08.282: E/AndroidRuntime(32767): at com.android.internal。 os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994) 08-23 21:26:08.282: E/AndroidRuntime(32767): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761) 08 -23 21:26:08.282: E/AndroidRuntime(32767): at dalvik.system.NativeStart.main(Native Method) 08-23 21:26:08.282: E/AndroidRuntime(32767): Caused by: java.lang. NullPointerException 08-23 21:26:08.282:E/AndroidRuntime(32767): 在 com.andytwistertrials_2.MainActivity.onCreate(MainActivity.java:60) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在 android.app.Activity.performCreate(Activity.java :5163) 08-23 21:26:08.282: E/AndroidRuntime(32767): 在 android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094) 08-23 21:26:08.282: E/AndroidRuntime(32767):在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061) 08-23 21:26:08.282: E/AndroidRuntime(32767): ... 11 更多282: E/AndroidRuntime(32767): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061) 08-23 21:26:08.282: E/AndroidRuntime(32767): ... 11 更多282: E/AndroidRuntime(32767): 在 android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061) 08-23 21:26:08.282: E/AndroidRuntime(32767): ... 11 更多

4

0 回答 0