我正在寻找一种方法,当用户长时间触摸地图视图(比方说1000毫秒),我可以执行某些操作。如何判断用户长时间按住地图视图(或任何视图)?这类似于Android Google Maps应用程序,当您长时间按住时,它会弹出气球覆盖物项。
编辑添加
编辑添加
mapView.setOnLongClickListener(new View.OnLongClickListener() {
public boolean onLongClick(View v) {
Toast.makeText(mapView.getContext(), "Hello 123", 2000);
return false;
}
});
上面的方法不起作用...有什么想法吗?
编辑添加
这是我目前尝试的方法,但似乎不起作用,即使我只在手机上按下它也会说事件是action_move,
我正在我的MapActivity中使用一个内部类。
private long startTime=0;
private long endTime=0;
class MapOverlay extends Overlay {
@Override
public boolean onTouchEvent(MotionEvent ev, MapView mapView) {
if(ev.getAction() == MotionEvent.ACTION_DOWN){
//record the start time
startTime = ev.getEventTime();
Log.d("LC", "IN DOWN");
}else if(ev.getAction() == MotionEvent.ACTION_UP){
//record the end time
endTime = ev.getEventTime();
Log.d("LC", "IN UP");
}else if(ev.getAction() == MotionEvent.ACTION_MOVE){
Log.d("LC", "IN move");
endTime=0;
}
//verify
if(endTime - startTime > 1000){
//we have a 1000ms duration touch
//propagate your own event
Log.d("LC", "time touched greater than 1000ms");
Toast.makeText(getBaseContext(), "Hello 123", Toast.LENGTH_SHORT).show();
startTime=0;
endTime=0;
return true; //notify that you handled this event (do not propagate)
}
return false;//propogate to enable drag
}
}
这是我的错误日志,但对我来说毫无意义
06-29 14:29:55.509: DEBUG/LC(7693): IN move
06-29 14:29:56.149: DEBUG/LC(7693): IN UP
06-29 14:29:56.149: DEBUG/LC(7693): 6346707 6349261
06-29 14:29:56.149: DEBUG/LC(7693): time touched greater than 1000ms
结束时间应该被设置为零...但它没有被设置...有什么想法为什么吗?
protected long _touchStartTime; public override bool OnTouchEvent(MotionEvent e){if (e.Action == MotionEventActions.Down) _touchStartTime = e.EventTime; if (e.Action == MotionEventActions.Up && e.EventTime - _touchStartTime > 1000) DoSomethingFun(); return base.OnTouchEvent(e);}
- BayssMekanique