Handle both onTap(GeoPoint p, MapView mapView) and onTap(int index) implemented in MapView

Refer to the last two post Detect touch, onTap(int index), on marker in MapView and Detect touch on MapView, onTap(GeoPoint p, MapView mapView); if both callback methods are implemented, onTap(GeoPoint p, MapView mapView) will always captured the event and onTap(int index) will never called.

Handle both onTap(GeoPoint p, MapView mapView) and onTap(int index) implemented in MapView

One of the solution is to call super method in onTap(GeoPoint p, MapView mapView). If super method have handled the event, return with true; otherwise perform as normal.

 @Override
public boolean onTap(GeoPoint p, MapView mapView) {
// TODO Auto-generated method stub

if(super.onTap(p, mapView)){
return true;
}

String title = "pt:" + String.valueOf(overlayItemList.size() + 1);
String snippet = "geo:\n"
+ String.valueOf(p.getLatitudeE6()) + "\n"
+ String.valueOf(p.getLongitudeE6());

addItem(p, title, snippet);

return true;
}

@Override
protected boolean onTap(int index) {
// TODO Auto-generated method stub
//return super.onTap(index);

Toast.makeText(context,
"Touch on marker: \n" + overlayItemList.get(index).getTitle(),
Toast.LENGTH_LONG).show();

return true;
}

Next:
- Switch Activity once a marker on a MapView tapped


0 Response to "Handle both onTap(GeoPoint p, MapView mapView) and onTap(int index) implemented in MapView"

Posting Komentar