views:

204

answers:

1

Hi I' trying to complete an assignment. I need to be able to draw circles with the canvas in Android and also draw the ten previous circles while my finger moves. I have saved the coordinates in an arraylist and tried to use a for loop to draw all of the circles. Here is my code, I'm just looking for suggestions not answers if anyone has any. I will attach my code. Right now it only draws one circle at a time.

`package edu.elon.cs.mobile;

import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Point; import android.graphics.Paint.Style; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.View;

import java.util.ArrayList;

/** * @author nfriederich * @version 1.0 Feb 23, 2010 * */ public class DotView extends View {

private ArrayList<Point> arlp;
private Paint marker;
private Point p;
private boolean update;

/**
 * @param aContext
 * @param aAttrs
 */
public DotView(Context aContext, AttributeSet aAttrs) {
    super(aContext, aAttrs);

    update = false;
    p = new Point();
    arlp = new ArrayList<Point>();
    marker = new Paint(Paint.ANTI_ALIAS_FLAG);
    marker.setColor(Color.YELLOW);
    marker.setStyle(Style.FILL);

}

@Override
public boolean onTouchEvent(MotionEvent event) {

    p.set((int) event.getX(), (int) event.getY());

    arlp.add(p);
    update = true;
    invalidate();
    return true;
}

@Override
protected void onDraw(Canvas cvs) {
    super.onDraw(cvs);
    if (update) {
        for (int i = 0; i < arlp.size(); i++) {
            cvs.drawCircle(arlp.get(i).x, arlp.get(i).y, 40, marker);

        }
    }

}

}`

A: 

Actually don't answer this there is some ambiguity on whether this is allowed within class policy.

NickTFried