Android: ItemizedOverlay onTouchEvent and onTap overlapping

前端 未结 3 1853
滥情空心
滥情空心 2020-12-15 14:49

I am trying to place a marker on a map overlay and then present a dialog when the user selects the drawable. The problem is the events seem to overlap. After I click the m

3条回答
  •  执念已碎
    2020-12-15 15:29

    I had exactly the same issue, my onTouchEvent added a marker to a map, and wanted it to show information about that marker when the user clicks on it, it worked but it also added another marker on top of it.

    So what I did was not use onTouchEvent but do everything in onTap(int index) and onTap(Geopoint p, MapView mapView) like so:

    public boolean onTap (final GeoPoint p, final MapView mapView){
        boolean tapped = super.onTap(p, mapView);
        if (tapped){            
            //do what you want to do when you hit an item           
        }           
        else{
            //do what you want to do when you DON'T hit an item
            }                   
        return true;
    }
    
    //Return true in order to say that the listener has correctly taken the event into account 
    @Override
    protected boolean onTap(int index) {
        return true;
    }
    

    Regards,

    Tom

提交回复
热议问题