目前,我有一个Android应用程序,可以在Google地图上放置图标。我想知道是否有办法使我的drawables可点击,所以我可以有一个弹出菜单给用户一些菜单选项。我正在实现这样的drawable:
Drawable drawable1 = Drawable.createFromStream(getAssets().open("pics/pin1.png"), null);
CustomItemizedOverlay itemizedOverlay1 = new CustomItemizedOverlay(drawable1, this);
GeoPoint point1 = new GeoPoint(latitudep1, longitudep1);
OverlayItem overlayitem1 = new OverlayItem(point1, "Icon", "#1");
itemizedOverlay1.addOverlay(overlayitem1);
mapOverlays.add(itemizedOverlay1);
提前致谢!
答案 0 :(得分:1)
试试这种方式
public class AddItemizedOverlay extends ItemizedOverlay<OverlayItem> {
private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
private Context context;
Intent intent;
MapView mapview;
public AddItemizedOverlay(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public AddItemizedOverlay(Drawable defaultMarker, Context context) {
this(defaultMarker);
this.context = context;
}
@Override
protected OverlayItem createItem(int i) {
return mapOverlays.get(i);
}
@Override
public int size() {
return mapOverlays.size();
}
@Override
protected boolean onTap(int index) {
OverlayItem item = mapOverlays.get(index);
/*intent = new Intent(context, Locationdisplay.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);// changed
Bundle bundle = new Bundle();
bundle.putString("namevalue", item.getTitle());
intent.putExtras(bundle);
context.startActivity(intent);*/
Toast.makeText(context, "tapped", 1).show();
return true;
}
public void addOverlay(OverlayItem overlay) {
mapOverlays.add(overlay);
this.populate();
}
}
答案 1 :(得分:0)
不确定是否可能,但您可以在地图上显示ImageViews而不是Drawables吗?使用ImageViews,可以很容易地使用它们上的点击事件。