当用户点击图标时,如何获取ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
的索引位置?例如,当用户点击/单击第一个图标时,它应该得到整数0
List<GeoPoint> nodes = nodeCoordinates();
ArrayList<OverlayItem> anotherOverlayItemArray = new ArrayList<>();
Drawable newMarker = getResources().getDrawable(R.drawable.marker_node);
for(int i = 0; i < nodes.size(); i++) {
anotherOverlayItemArray.add(new OverlayItem("Road", "Nodes", nodes.get(i)));
anotherOverlayItemArray.get(i).setMarker(newMarker);
}
ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
= new ItemizedIconOverlay<>(
this, anotherOverlayItemArray, null);
map.getOverlays().add(anotherItemizedIconOverlay);
答案 0 :(得分:1)
确认,格式化问题......
`
itemOverlay = new ItemizedOverlayWithFocus&lt;&gt;(new ArrayList(), new ItemizedIconOverlay.OnItemGestureListener(){ @覆盖 public boolean onItemSingleTapUp(final int index,final OverlayItem item){ Toast.makeText( 背景下, &#34;项目&#39;&#34; + item.getTitle()+&#34;&#39; (index =&#34; + index +&#34;)单击“#34;,Toast.LENGTH_LONG)。show(); 返回true; }
@Override
public boolean onItemLongPress(final int index, final OverlayItem item) {
Toast.makeText(
context,
"Item '" + item.getTitle() + "' (index=" + index
+ ") got long pressed", Toast.LENGTH_LONG).show();
return false;
}
}, context);
`