Попробуйте: у меня есть класс GenesMotionDetector.java.Вот код для этого:
package gene.com.motioneventssample;
import android.app.Activity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
//This works
public class GenesMotionDetector extends Activity implements GestureDetector.OnGestureListener {
private GestureDetector gestureScanner;
LinearLayout mView1;
TextView mView2;
ImageView mView3;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nothing);
gestureScanner= new GestureDetector(getBaseContext(),this);
}
@Override
public boolean onTouchEvent(MotionEvent me) {
System.out.println("Inside onTouchEvent() of GenesMotionDetector.java");
return gestureScanner.onTouchEvent(me);
}
@Override
public boolean onDown(MotionEvent e) {
System.out.println("Inside onDown() of GenesMotionDetector.java");
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
System.out.println("Inside onFling() of GenesMotionDetector.java");
return true;
}
@Override
public void onLongPress(MotionEvent e) {
System.out.println("Inside onLongPress() of GenesMotionDetector.java");
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
System.out.println("Inside onScroll() of GenesMotionDetector.java");
return true;
}
@Override
public void onShowPress(MotionEvent e) {
System.out.println("Inside onShowPress() of GenesMotionDetector.java");
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
System.out.println("Inside onSingleTapUp() of GenesMotionDetector.java");
return true;
}
}
Соответствующий XML-файл макета для этого класса - none.xml.Вот код для этого:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/screen"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text"
android:background="#17528c"
android:text="testing"
android:layout_width="100dp"
android:layout_height="200dp" />
<ImageView
android:id="@+id/image"
android:background="#f8af20"
android:layout_width="100dp"
android:layout_height="200dp" />
</LinearLayout>