本文介绍了Android的图形页面的onTap方法去除所有点后不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时,有最低在地图上的一个点,但是当我从地图中移除所有的点,然后中的onTap()方法不工作,我无法在地图上添加点和Ontap()方法的工作。

The onTap() method working when there is minimum one point on map but when I remove all points from map then onTap() method is not working and I am unable to add points on map.

请帮忙...

code:

    private class CustomItemizedOverlay2 extends ItemizedOverlay<OverlayItem> {

    private ArrayList<OverlayItem> mapOverlays = new ArrayList<OverlayItem>();
    private Context context;
    private GeoPoint center = null;

    public CustomItemizedOverlay2(Drawable defaultMarker) {
        super(boundCenterBottom(defaultMarker));
    }

    public CustomItemizedOverlay2(Drawable defaultMarker, GeoPoint point) {
        this(defaultMarker);
        OverlayItem overlayItem = new OverlayItem(point, "", "");
        mapOverlays.add(overlayItem);
        populate();
    }

    public CustomItemizedOverlay2(Drawable defaultMarker, Context context,
            String result) {
        this(defaultMarker);
        this.context = context;

        for (int i = 0; i < geoPointList.size(); i++) {
            OverlayItem overlayItem = new OverlayItem(geoPointList.get(i),
                    "abc", "point" + i);
            mapOverlays.add(overlayItem);
        }
        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return mapOverlays.get(i);
    }

    @Override
    public int size() {
        return mapOverlays.size();
    }

    @Override
    public boolean onTap(GeoPoint point, MapView mapView) {

        int size = geoPointList.size();
        if (size < 2) {
            geoPointList.add(point);

            count++;
            int lat = point.getLatitudeE6();
            int longi = point.getLongitudeE6();
            Drawable image = gMap.this.getResources().getDrawable(
                    R.drawable.pushpin);

            CustomItemizedOverlay2 addPointItemizedOverlay = new CustomItemizedOverlay2(
                    image, point);
            mapView.getOverlays().add(addPointItemizedOverlay);


            mapView.invalidate();
        }
        return super.onTap(point, mapView);
    }



}

的的onTap方法添加点,如果在geoPointList点的数目是小于2。

The onTap method add point if the number of points in geoPointList is less than two.

推荐答案

终于解决了,因为我已经实现自定义MapOverlay,并在其使用中的onTap方法,而不是使用CustomItemizedOverlay2的。

Finally solved, as I have implemented the custom MapOverlay and use the onTap method in it instead of using in CustomItemizedOverlay2.

这篇关于Android的图形页面的onTap方法去除所有点后不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 14:48