开发者

Android For Loop Not stopping

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);
            i开发者_开发知识库nvalidate();
            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 =


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜