onTouchEvent无法在android中运行 [英] onTouchEvent not working in android

查看:136
本文介绍了onTouchEvent无法在android中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Override
 public boolean onTouchEvent(MotionEvent event) {
  // TODO Auto-generated method stub


  switch(event.getAction()){
  case MotionEvent.ACTION_DOWN:
  case MotionEvent.ACTION_MOVE:
   float x = event.getX();
   float y = event.getY();

   Toast.makeText(this, "Touched@" + x + " : " + y, Toast.LENGTH_LONG).show();
  // ((AndroidDetechTouchActivity)getContext()).updateMsg("Touched@" + x + " : " + y);
   break;
  case MotionEvent.ACTION_UP:
 //  ((AndroidDetechTouchActivity)getContext()).updateMsg("");
   break;
  }

  return true;
 }

推荐答案

确保如果你在模拟器中运行那么你应该添加触摸硬件

如果你在设备中使用那么



检查你必须用于触摸列表的权限
make sure if you are running in emulator then you should have to add touch hardware
and if you are using in device then

check the permission you have to use for touch listner


这篇关于onTouchEvent无法在android中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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