开发者

Class inside of for loop

newbie, I have class:

class PolyOverlay extends Overlay {

    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow)
    {

        try {

        List<GeoPoint> points = new ArrayList<GeoPoint>();
        GeoPoint tmpPoint;

        double lat2;
        double lng2;

        String args[] = {"",""};
        args = sitesList.getpolyLine().get(daI).split("\\;");
        //Toast.makeText(getApplicationContext(),"T: " + args[0],Toast.LENGTH_SHORT ).show();


        for (int i = 0; i < args.length; i++) {
            String coordinates2[] = {"",""};
            String args2[] = {"",""};
            args2 = args[i].split("\\,");

            coordinates2[0]= args2[0];
            coordinates2[1]= args2[1];

          //Toast.makeText(getApplicationContext(),"T: " + coordinates2[0],Toast.LENGTH_SHORT ).show();


            lat2= Double.parseDouble(coordinates2[0]);
            lng2= Double.parseDouble(coordinates2[1]);
            tmpPoint = new GeoPoint((int) (lat2 * 1E6), (int) (lng2 * 1E6) );                   
            points.add(tmpPoint);


        }


        //for(Polygon polygonTemp : polygonList)
        //{           
            Path p = new Path();
            Projection projection = mapView.getProjection();

            boolean firstTime = true;
            for(GeoPoint geoPoint : points)
            {
                Point drawPoint = new Point();
                projection.toPixels(geoPoint, drawPoint);

                if(firstTime)
                {
                    p.moveTo(drawPoint.x, drawPoint.y);
                    firstTime = false;
                }
                else
                {
                    p.lineTo(drawPoint.x, drawPoint.y);
                }
            }
            p.setFillType(Path.FillType.EVEN_ODD);

            Paint polyPaint = new Paint();
            polyPaint.setStrokeWidth(1);
            polyPaint.setStyle(Paint.Style.FILL_AND_STROKE);
            polyPaint.setAntiAlias(true);
            polyPaint.setColor(Color.BLUE);
            polyPaint.setAlpha(30);
            canvas.drawPath(p, polyPaint);
            firstTime = true;
        //}
        super.draw(canvas, mapView, shadow);
        } catch (Exception e) {
            Toast.makeText(epapp.this, "Err: " + e, Toast.LENGTH_LONG).show();

        }
    }

}

Then inside an xml loop I do this:

for (int i = 0; i < sitesList.getStrap().size(); i++) {

            //icons

            String pargs[] = sitesList.getCentr().get(i).split("\\,");

            String coordinates3[] = {"",""};
            coordinates3[0] = pargs[0].toString();
            coordinates3[1] = pargs[1].toString();

            //Toast.makeText(epapp.this, "Center: " + coordinates3[0], Toast.LENGTH_LONG).show();

            double lat2 = Double.parseDouble(coordinates3[0]);
            double lng2 = Double.parseDouble(coordinates3[1]);



            np = new GeoPoint(
                (int) (lat2 * 1E6), 
                (int) (lng2 * 1E6)); 
            Drawable drawable = this.getResources().getDrawable(R.drawable.iconresidential);
            IconItemizedOverlay itemizedoverlay = new IconItemizedOverlay(drawable,this);


            OverlayItem overlayitem = new OverlayItem(np, "Property Information", "JONES EMERSON ROBERT JR & SARA MARIA<br>1032 Briarwood Dr Wauchula 33873<br>HARDEE County<br>STRAP 05-34-25-0865-00001-0020");
            itemizedoverlay.addOverlay(overlayitem);
            mapView.getOverlays().add(itemizedoverlay);


            //if (i==1){


        //polyString = sitesList.getpolyLine().get(i);
        daI=i;  
        //polygon

            PolyOverlay myPolyOverlay = new PolyOverlay();
            mapView.getOverlays().add(myPolyOverlay);

                   //}  

        }

ok so the "problem" is if I do the //if (i==1){ part in the loop where "daI" is being set to "i", my "Polygon" is displayed on the map for that item in the XML, if I "REM" it out, the Polygon(s) overlay are always the last item in the XM开发者_如何学PythonL. The xml list has 20 items in the list always and it seems as if the the "daI" variable is always 19 (last index in the list 0-19)

Obviously not do something so the PolyOverlay class gets "finished" before the xml loop is done?? It like the xml loop flys through sets "daI" to the last one and the PolyOverlay is loading the polygon for that last item...

My icons are just fine btw on the map...


k, I'm retarded: I had to do this:

   int di = 0;

    PolyOverlay(int n) {
        di = n;
    }

in my PolyOvelay class then pass the "i" from the xml for loop to it...

PolyOverlay myPolyOverlay = new PolyOverlay(i);

mapView.getOverlays().add(myPolyOverlay);

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜