强制关闭onClick的ImageButton,不知道为什么

我试图用ImageButtons做一个简单的动画,当我设置它时,如果我只是触摸屏幕,它的工作原理很好,但如果我尝试在onClick上做,它会关闭。

main.xml中

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal">
       <ImageButton
        android:id="@+id/plus1"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:src="@drawable/plus"
        android:visibility="visible" 
        android:gravity="center_horizontal"
        android:onClick="RunAnimations" 
        />

    <ImageButton
        android:id="@+id/gears1"
        android:layout_width="75dp"
        android:layout_height="75dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:background="@null"
        android:gravity="center_horizontal"
        android:src="@drawable/gears"
        android:textSize="42sp" />
    </LinearLayout>

translate.xml

<?xml version="1.0" encoding="utf-8"?>
<set>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromYDelta="-100%"
    android:toYDelta="0%"
    android:duration="1000"
    android:zAdjustment="top" >
</translate>

<alpha
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="1000">
</alpha>
</set>

主要活动:


    public class AnimationtestActivity extends Activity  {
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
        }
        private void RunAnimations() {
            Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);
            View ib = findViewById(R.id.gears1);
            ib.clearAnimation(); 
            ib.startAnimation(a);     
        }
    }

编辑:

我修复了私人无效的RunAnimations(View视图)

但它仍然强制关闭

编辑2:logcat的内容

03-08 13:07:33.968: E/AndroidRuntime(29270): FATAL EXCEPTION: main
03-08 13:07:33.968: E/AndroidRuntime(29270): java.lang.IllegalStateException: Could not find a method RunAnimations(View) in the activity class com.test.AnimationtestActivity for onClick handler on view class android.widget.ImageButton with id 'plus1'
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View$1.onClick(View.java:3026)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View.performClick(View.java:3480)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View$PerformClick.run(View.java:13983)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.os.Handler.handleCallback(Handler.java:605)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.os.Looper.loop(Looper.java:137)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.app.ActivityThread.main(ActivityThread.java:4340)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.reflect.Method.invokeNative(Native Method)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.reflect.Method.invoke(Method.java:511)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at dalvik.system.NativeStart.main(Native Method)
03-08 13:07:33.968: E/AndroidRuntime(29270): Caused by: java.lang.NoSuchMethodException: RunAnimations [class android.view.View]
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.Class.getConstructorOrMethod(Class.java:460)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at java.lang.Class.getMethod(Class.java:915)
03-08 13:07:33.968: E/AndroidRuntime(29270):    at android.view.View$1.onClick(View.java:3019)
03-08 13:07:33.968: E/AndroidRuntime(29270):    ... 11 more

该框架找不到您的点击处理程序方法,因为它具有错误的签名。 声明它是这样的:

public void RunAnimations(View view) {
    . . .
}
链接地址: http://www.djcxy.com/p/96147.html

上一篇: Force close onClick of ImageButton, can't figure out why

下一篇: undefined reference to `