OSM中如何获取被点击的ItemizedIconOverlay的index
How to get the index of the clicked ItemizedIconOverlay in OSM
如何在用户点击图标时获取 ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
的索引位置?例如,当用户 taps/clicks 第一个图标时,它应该得到整数 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);
确认,格式问题....
`
itemOverlay = new ItemizedOverlayWithFocus<>(new ArrayList(),
新 ItemizedIconOverlay.OnItemGestureListener() {
@覆盖
public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
Toast.makeText(
语境,
"Item '" + item.getTitle() + "' (index=" + index
+ ") 单次点击", Toast.LENGTH_LONG).show();
return 真;
}
@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);
`
如何在用户点击图标时获取 ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
的索引位置?例如,当用户 taps/clicks 第一个图标时,它应该得到整数 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);
确认,格式问题....
`
itemOverlay = new ItemizedOverlayWithFocus<>(new ArrayList(), 新 ItemizedIconOverlay.OnItemGestureListener() { @覆盖 public boolean onItemSingleTapUp(final int index, final OverlayItem item) { Toast.makeText( 语境, "Item '" + item.getTitle() + "' (index=" + index + ") 单次点击", Toast.LENGTH_LONG).show(); return 真; }
@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);
`