开发者

How to make an overlapped image clickable in android?

开发者 https://www.devze.com 2023-04-08 04:47 出处:网络
I have a image of a map and i want t开发者_JS百科o plot some points/markers on the map. These markers must be clickable. I have used a custom view class to plot the markers at my required points.The m

I have a image of a map and i want t开发者_JS百科o plot some points/markers on the map. These markers must be clickable. I have used a custom view class to plot the markers at my required points.The markers are getting plotted but the problem is that either the marker is not clickable or when i set onClick listener on the custom view,the whole image receives the click event(whereever i click on image, onClick is called,but i want only click on the marker to initiate onClick). Can someone please help me with this?


You have to create your custom MapOverlay and inside put the code the function. In this code above, Override the OnTap method.

  public class MapOverlay extends ItemizedOverlay {

private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Context mContext;

public MapOverlay(Drawable defaultMarker,Context context) {
    super(boundCenterBottom(defaultMarker));
    mContext = context;
}

@Override
protected OverlayItem createItem(int i) {
    // TODO Auto-generated method stub
    return mOverlays.get(i);
}

public void addOverlay(OverlayItem overlay) {
    mOverlays.add(overlay);
    populate();
}

public void clearOverlay() {
    mOverlays.clear();
    populate();
}
@Override
public int size() {
    // TODO Auto-generated method stub
    return mOverlays.size();
}



@Override
protected boolean onTap(int index) {
  OverlayItem item = mOverlays.get(index);
  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
  dialog.setTitle(item.getTitle());
  dialog.setMessage(item.getSnippet());
  dialog.show();
  return true;
}

}

0

精彩评论

暂无评论...
验证码 换一张
取 消