0

我有一个小问题。基本上我想要做的是绘制航点到地图,触摸。但我想在添加一个航点后停止 onTouch 方法,因为现在它只需单击即可添加更多航点,然后继续添加它们下一步触及。

方法如下

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==RESULT_OK)
    {
        final MapPoint point=(MapPoint) data.getSerializableExtra("result");
         GeoPoint point2 = new GeoPoint(51496994, -134254);
         point.setGeo(point2);



                    view.setOnTouchListener(new View.OnTouchListener()
                    {

                        @Override
                        public boolean onTouch(View v, MotionEvent e) {
                            GeoPoint geo = null;
                            IProjection project = view.getProjection();
                            geo=(GeoPoint)project.fromPixels((int)e.getX(),(int)e.getY());
                            mainDrawer.addGeopointToMap(point.getName(), point.getDesc(), geo);
                            return false;
                        }});
    }
4

2 回答 2

2

您可以简单地将 actionListener 设置为null 这将使操作在第一次被调用,然后它将为 null 所以它不会再次调用。

        view.setOnTouchListener(new View.OnTouchListener()
        {

                    @Override
                    public boolean onTouch(View v, MotionEvent e) {
                        GeoPoint geo = null;
                        IProjection project = view.getProjection();
                        geo=(GeoPoint)project.fromPixels((int)e.getX(),(int)e.getY());
                        mainDrawer.addGeopointToMap(point.getName(), point.getDesc(), geo);
                        view.setOnTouchListener(null)
                        return false;
                    }});
        }
于 2013-04-03T14:30:30.983 回答
1

只需使用布尔标志:

boolean added = false;
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==RESULT_OK) {
        final MapPoint point=(MapPoint) data.getSerializableExtra("result");
        GeoPoint point2 = new GeoPoint(51496994, -134254);
        point.setGeo(point2);
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent e) {
                if(!added) {
                    GeoPoint geo = null;
                    IProjection project = view.getProjection();
                    geo=(GeoPoint)project.fromPixels((int)e.getX(),(int)e.getY());
                    mainDrawer.addGeopointToMap(point.getName(), point.getDesc(), geo);
                    added = true;
                 }
                 return false;
            }});
}
于 2013-04-03T14:13:52.850 回答