0

在我的应用程序中,我将 googlemaps 用于该一项主要活动,并在 googlemaps 上用于该覆盖类的免费手绘草图。对于这个用于存储路径的手绘草图,覆盖类中使用了一个数组列表。接下来在主要活动中执行撤消和重做功能,因此我必须在主要活动中使用数组列表,因为我将覆盖类中的数组列表声明为公共静态。使用静态我得到了连续绘图,这是我的问题..如何在我的应用程序中使用数组列表而不使用静态....

public class HandDrawOverlay extends Overlay {

   private boolean iseditMode = true;
   private boolean isTouched = false;
   private Paint paint = new Paint();
   private Point screenPt1 = new Point();
   private Point screenPt2 = new Point();
   public static ArrayList<GeoPoint> points = new ArrayList<GeoPoint>();    
   int x, y;
   GeoPoint geoP;
   HandDrawOverlay handDrawOverlay;
   private GoogleMapActivity mview = null;
   private boolean isUp = false;     

   public HandDrawOverlay(GoogleMapActivity mapviewdata){

      paint.setStrokeWidth(4.0f);
      paint.setStyle(Style.STROKE);
      paint.setColor(Color.BLUE);
      mview = mapviewdata;       
   }

   public static ArrayList<GeoPoint>  getBitmap(){
          return points;
   }   

   @Override
   public void draw(Canvas canvas, MapView mapView, boolean shadow) {    
    if (points != null && points.size() > 1) {           
        mapView.getProjection().toPixels(points.get(0), screenPt1);

        for (int i = 1; i < points.size(); i++) {            
            mapView.getProjection().toPixels(points.get(i), screenPt2);
            canvas.drawLine(screenPt1.x, screenPt1.y, screenPt2.x, screenPt2.y, paint);
            screenPt1.set(screenPt2.x, screenPt2.y);                 
        }
     }
  }

   @Override
   public boolean onTouchEvent(MotionEvent e, MapView mapView) {
    if(mview.isEditMode() && (iseditMode)){         

        x = (int) e.getX();
        y = (int) e.getY();           
        geoP = mapView.getProjection().fromPixels(x, y);    
        Log.i("", "geoP" +geoP);

        switch (e.getAction()) {
        case MotionEvent.ACTION_DOWN:                            
            isTouched = true;        
            points.add(geoP);                               
            break;              

        case MotionEvent.ACTION_MOVE:            
            if (isTouched = true)
                points.add(geoP);               
            break;

        case MotionEvent.ACTION_UP:          
            if (isTouched = true)
                points.add(geoP);                    
            isUp = true;
            handDrawOverlay = new HandDrawOverlay(mview);
            mapView.getOverlays().add(handDrawOverlay);
            break;
        }           
        mapView.postInvalidate();    
        return true;            
      }      
       return false;
   }     
}
4

1 回答 1

0

为此,您可以使用它。

public class Hiroshima {

    private static Hiroshima hr = new Hiroshima();


    public ArrayList<String> mImages = new ArrayList<String>();


      private Hiroshima(){}

      public static Hiroshima getInstance(){

          return hr;
      }

}

现在你可以从任何地方使用这个 ArrayList。它会给你相同的实例。

在您的活动中写下如下。

Hiroshima hx = Hiroshima.getInstance();
于 2012-11-02T06:16:29.380 回答