我有一个自定义的 OnTouch 方法,我检查触摸坐标是否包含一个矩形。检查条件后我想开始一个新的 Activity。但不幸的是它不起作用。有人可以帮我吗?
public class custom extends SurfaceView implements SurfaceHolder.Callback{
public boolean onTouchEvent(MotionEvent event) {
int touchX = (int) event.getX();
int touchY = (int) event.getY();
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
System.out.println("Touching down!");
for(int i =0; i< rectangles.size();i++){
if(rectangles.get(i).contains(touchX,touchY)){
System.out.println("Touched Rectangle, start activity.");
rectangles.get(i).describeContents ();
Selected_rect = String.valueOf(rectangles.get(i));
}
Intent intent=new Intent(getContext(), DetectBlock.class);
startActivity(intent); //ERROR >> Start activity undefined
}
break;
case MotionEvent.ACTION_UP:
System.out.println("Touching up!");
break;
case MotionEvent.ACTION_MOVE:
System.out.println("Sliding your finger around on the screen.");
break;
}
return true;
}
}