Skip to content

Instantly share code, notes, and snippets.

@ilguzin
Created November 29, 2012 13:28
Show Gist options
  • Save ilguzin/4169068 to your computer and use it in GitHub Desktop.
Save ilguzin/4169068 to your computer and use it in GitHub Desktop.
Simple way of making long tap event work in MapView. MapActivity class
public class MyMapActivity extends MapActivity
implements OnGestureListener {
...
private GestureDetector gestureDetector;
@Override
public void onCreate(...) {
super.onCreate(...);
setContentView(R.layout.mymapviewlayout);
this.gestureDetector = new GestureDetector(this);
this.gestureDetector.setIsLongpressEnabled(true);
this.mapView = (MapView)findViewById(R.id.myMapView);
this.mapView.set....
...
this.mapView.setClickable(true);
...
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int actionType = ev.getAction();
switch (actionType) {
case MotionEvent.ACTION_MOVE:
//react properly
break;
}
return gestureDetector.onTouchEvent(ev);
}
...
//other methods of the OnGestureListener interface
public void onLongPress(MotionEvent e) {
ActivityUtils.showToast(this, "Pushed down", 3000);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment