0

このコードの問題は何ですか?

package com.evorlor.samplecode;

import android.app.Activity;

public class MotionEvent extends Activity {

    public boolean onTouchEvent(MotionEvent me) {
        int i = me.getAction();

        switch (i) {

        case MotionEvent.ACTION_DOWN:
            // When your finger touches the screen

            break;

        case MotionEvent.ACTION_UP:
            // When your finger stop touching the screen

            break;

        case MotionEvent.ACTION_MOVE:
            // When your finger moves around the screen

            break;
        }

        return false;
    }

}

エラーが発生しています:

メソッドgetAction()は、.getAction()のタイプMotionEventに対して未定義です。インポートできません:

import android.view.MotionEvent;

私が知る限り、これはこの動作するコードと同じです(import android.view.MotionEvent;をインポートできないことを除けば):

package com.evorlor.counter;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.TextView;

public class Counter extends Activity {

    private static int count = 0;
    private static int hiCount = 0;
    private static boolean capCount = false;
    public static boolean resetCount = false;
    public static boolean askReset = false;

    public boolean onTouchEvent(MotionEvent me) {
        if (me.getAction() == MotionEvent.ACTION_UP) {
            count++;
        }

        onCreate(null);

        return false;
    }
}

助けてくれてありがとう!

4

2 に答える 2

4

アクティビティの名前を別の名前に変更します。これは、必要な実際のMotionEventクラスと競合しています。

于 2012-12-18T04:25:57.267 に答える
1

定義したクラス名はandroid.view.MotionEventを非表示にします

public class MotionEvent

クラス名を変更するだけで、問題は解決します

于 2012-12-18T04:25:54.643 に答える