0

我为表面视图创建了一个 TapGestureDetector 类。在那里我捕捉到了长触摸事件,我想开始一个新的活动。但它不起作用。Intent 没有启动。有一个空指针异常。我已经在清单中定义了动作以及意图。但是有一个我无法识别的错误。

 public class TapGestureDetector extends GestureDetector.SimpleOnGestureListener {

int touchX;
int touchY;
public static String block_name;
Context ctx = custom.ctx;
ArrayList<Rect> rectangles = storeMap.GetArrayList();


@Override
public void onLongPress(MotionEvent event) {

//Detect touched X.Y
    touchX = (int) event.getX();
    touchY = (int) event.getY();
//Go through a set of rectangles and identify the touched rectangle
    for (int i = 0; i < rectangles.size(); i++) {

        if (rectangles.get(i).contains(touchX, touchY)) {

            rectangles.get(i).describeContents();
            String Selected_rect = String.valueOf(rectangles.get(i));
            Store_Identified_Block.Store(Selected_rect);
            getSelectedCoordinates();


            //Start a new intent
            Intent myIntent = new Intent("android.intent.action.zoomlevel");
            myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            //This is not working
            try {
                ctx.startActivity(myIntent);
            } catch (Exception e) {

                Log.d("onLongPress(MotionEvent event)", e.toString());
                e.printStackTrace();
            }



            break;
        }
    }

super.onLongPress(event);
}
4

1 回答 1

0

解决了:)

try {

                Intent mm=new Intent(finalmainvclass.maincontaxt,zoomlevel.class);
                mm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                finalmainvclass.maincontaxt.startActivity(mm);

            } catch (Exception e) {

                Log.d("MYLOG", "Error is "+e.toString());
                e.printStackTrace();
            }
于 2012-11-08T15:58:31.727 回答