为什么 MapView onTouchListener 只触发一次?
我想检测用户对地图进行的每次触摸,因此我为 MapView 实例注册了一个侦听器。然而,这个监听器只被调用一次,之后如果我想让它再次工作,我需要关闭应用程序。我正在使用 OsmDroid。
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
System.out.println("OnTouch MapView Listener!");
return false;
}
});
Possible Duplicate:
OnTouch in MapView only fires the first time
I want to detect every touch made by the user to the map and hence I have registered a listener for an instance of MapView. However, this listener only get called once, after that I need to close the application if I want it to work again. I am using OsmDroid.
mMapView = (MapView) findViewById(R.id.mapview);
mMapView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
System.out.println("OnTouch MapView Listener!");
return false;
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您是否尝试过返回 true 而不是 false?也许存在一个问题,因为您实际上并没有消耗它徘徊的触摸事件,这会阻止再被调用。
Have you tried returning true instead of false? Mabey there is an issue since your not actually consuming the touch event that it's lingering around which is prevent anymore from being called.
我也无法让它多次工作。我最终添加了一个不执行任何操作的覆盖层,并在覆盖层中放置了一个 onTouchEvent() 。这有效
I could never get it to work more than once either. I ended up adding an overlay which does nothing and putting an onTouchEvent() in the overlay. This worked