ItemizedOverlay<>
クラスを拡張してメソッドをオーバーライドする必要がありonTap()
ます。
このようなもの:
public class MapOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlay = new ArrayList<OverlayItem>();
Context mContext;
public MapOverlay(Drawable itemMarker) {
super(boundCenterBottom(itemMarker));
// TODO Auto-generated constructor stub
}
public void addItem(OverlayItem item){
mapOverlay.add(item);
populate();
}
@Override
protected OverlayItem createItem(int i) {
// TODO Auto-generated method stub
return mapOverlay.get(i);
}
@Override
public int size() {
// TODO Auto-generated method stub
return mapOverlay.size();
}
public MapOverlay(Drawable itemMarker, Context context){
super(boundCenterBottom(itemMarker));
mContext = context;
}
@Override
protected boolean onTap(int index) {
// TODO Auto-generated method stub
final OverlayItem item = mapOverlay.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setTitle(item.getTitle());
dialog.setMessage(item.getSnippet());
dialog.show();
return true;
}
}
アイテムを追加するアクティビティで:
Drawable voltaIcon = this.getResources().getDrawable(R.drawable.arch);
MapOverlay volte = new MapOverlay(voltaIcon, this);
GeoPoint p_Volta = new GeoPoint(45373024, 14348799);
OverlayItem volta = new OverlayItem(p_Volta,
getResources().getStringArray(R.array.volta)[0],
getResources().getStringArray(R.array.volta)[1]);
volte.addItem(volta);