如何打开里面OnTouch事件的新意图是什么? [英] How to open a new Intent inside OnTouch Event?

查看:142
本文介绍了如何打开里面OnTouch事件的新意图是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义的OnTouch方法,其中我检查触摸坐标包含rectangle.After检查我要开始一个新的Activity.But unfortuanlely它不是workin.Can有人能帮助我的条件?

 公共类的自定义扩展SurfaceView实现SurfaceHolder.Callback {


公共布尔的onTouchEvent(MotionEvent事件){
    INT touchX =(INT)event.getX();
    INT敏感=(INT)event.getY();
    开关(event.getAction()){

    案例MotionEvent.ACTION_DOWN:
            的System.out.println(接触下来!);

            的for(int i = 0; I< rectangles.size();我++){

                如果(rectangles.get(I)。载(touchX,敏感)){
                    的System.out.println(感动矩形,开始活动。);
                    rectangles.get(ⅰ).describeContents();
                    Selected_rect =将String.valueOf(rectangles.get(一));
                                       }
                意向意图=新的意图(的getContext(),DetectBlock.class);
                startActivity(意向); //错误>>启动活动未定义

            }
            打破;
    案例MotionEvent.ACTION_UP:
            的System.out.println(接触了!);
            打破;
    案例MotionEvent.ACTION_MOVE:
            的System.out.println(在屏幕上滑动手指左右。);
            打破;
    }
    返回true;
}
}
 

解决方案

我找到了答案:)

 私人无效startActivity(){
    // TODO自动生成方法存根
    意图myIntent =新的意向书(android.intent.action.DetectBlock);
    myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    。的getContext()startActivity(myIntent);
}
 

I have a customized OnTouch Method where i check if the touch coordinates contains a rectangle.After checking the condition i want to start a new Activity.But unfortuanlely its not workin.Can someone help me out?

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;
}
}

解决方案

I found the answer :)

private void startActivity() {
    // TODO Auto-generated method stub
    Intent myIntent = new Intent("android.intent.action.DetectBlock");
    myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    getContext().startActivity(myIntent);
}

这篇关于如何打开里面OnTouch事件的新意图是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆