Reputation: 15
I'm playing around with 2 d graphics on android. I'm using random generator for x and y using a for loop. weird thing is that the loop never stops:
for (int i = 0; i < 5; i++){
System.out.println(i);
invalidate();
int randomX = randomGenerator.nextInt(1000);
int randomY = randomGenerator.nextInt(1000);
canvas.drawPoint(randomX, randomY, paint);
float radius = 20;
canvas.drawCircle(randomX, randomY, radius, paint);
}
i look at the logcat it shows i = 0,1,2,3,4. am i going blind??? i =
Upvotes: 1
Views: 385
Reputation: 56
If your for
loop is inside the onDraw()
method of a view, calling invalidate()
will force the view to redraw itself, calling onDraw()
again, thus the infinite loop.
Upvotes: 2