Original Question: I am trying to draw rectangles on the canvas one after the other. I would like to pause for a second before drawing each object. How would I implement this feature?
EDIT: This is the code that I have working so far. Not sure if this is the best practice. Suggest a better way if you know one.
boolean stopAnimation = false;
int currentRectangle = 0;
Handler handler = new Handler(){
public void handleMessage(android.os.Message msg) {
invalidate();
System.out.println("redraw"+currentRectangle);
currentRectangle++;
if(currentRectangle>2){
stopAnimation = true;
}
};
};
public void onDraw(final Canvas canvas) {
final Rect currentRect = new Rect(a, 0, b, c);
canvas.drawRect(currentRect, paint); //wait a lil bit
canvas.drawRect(newRect, paint);
}
public void run() {
while (!stopAnimation) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(0);
}
}