我对onTap方法以及它们如何与ItemizedOverlay一起工作感到有点困惑。我想让用户在地图上点击,然后在他们点击的地方放置一个OverlayItem (图标)。然后我要他们再次点击那个OverlayItem来确认位置。
我可以通过重写将OverlayItem添加到地图中,这没有问题
public boolean onTap(GeoPoint p, MapView mapView)但是,我想通过重写来捕获用户点击该项目
protected boolean onTap(int i)问题是,当我重写这两个方法时,当我点击我的图标项目时,第二个方法永远不会执行。
我遵循了所有的例子,但我仍然被卡住了。有人能告诉我我哪里做错了吗?
谢谢
发布于 2010-12-19 00:54:06
谢谢你的回复。super.onTap似乎是我错过的东西。这些都是我的方法,所以你可以看到onTap的'GeoPoint‘版本是主要的入口点,而且它是有效的!我发布的链接也很有帮助。
@Override
public boolean onTap(GeoPoint p, MapView mapView) {
// If it was the parent that was tapped, do nothing
if(super.onTap(p, mapView)) {
return true;
}
else {
lastClickedLocation = p;
mapView.getController().animateTo(lastClickedLocation);
if(markerItem == null) {
markerItem = new OverlayItem(lastClickedLocation, "", "");
items.add(markerItem);
}
else {
items.remove(markerItem);
markerItem = new OverlayItem(lastClickedLocation, "", "");
items.add(markerItem);
}
Utils.alert(parent.getApplicationContext(), parent.getResources().getString(R.string.tapAgainToConfirm));
populate();
return true;
}
}
/**
* Override the onTap(index) method
*/
@Override
protected boolean onTap(int i) {
parent.confirmLocation(items.get(i));
return true;
}发布于 2010-12-18 21:46:52
我还没有尝试过,但我认为它会起作用的:
尝试从GeoPoint-flavored onTap()链接到超类。这将为您提供调用索引风格的onTap()的默认处理。重写该方法以找出用户何时点击现有标记,并返回true以指示您处理了该事件。回到GeoPoint-flavored onTap()中,如果super.onTap()返回true,则表示事件已由某人(如您)处理。因此,如果它是false,则在提供的GeoPoint处添加一个标记。
https://stackoverflow.com/questions/4477469
复制相似问题