0
我写了一些代码来从ImageView中获取位置。下面是我的代码:如何在MotionEvent的参数中添加
private void touchLocation(MotionEvent e){
float x = e.getX();
float y = e.getY();
String message = "Location is x = " + x + ", y = " + y ".";
Context context = getApplicationContext();
int duration = Toast.LENGTH_LONG:
Toast toast = Toast.makeText(context, message, duration);
toast.show();
}
在onCreate()方法,如何将我调用这个函数?任何建议,非常感谢。我应该如何用类MotionEvent实例化一个对象?
我得到错误“类型View中的方法setOnTouchListener(View.OnTouchListener)不适用于参数(new OnTouchListener(){})”。为什么?以及如何解决它? – 2014-12-05 19:14:23
确保您正确导入了侦听器,您需要在其他导入文件的顶部导入“android.view.View.OnTouchListener;'。 – 2014-12-05 19:18:41
感谢Petr Duchek。它解决了所有问题。 – 2014-12-05 19:23:59