I want to generate circles every 2 seconds, in this case 5 but I can't get it. Instead of creating a circle every 2 seconds, the app wait 10 seconds and draw the 5 circles together. What am I doing wrong?
public class Juego extends SurfaceView{
boolean isItOK = false;
Paint paint;
int CantidadDeEsferas = 5;
int radio, alto, ancho;
public Juego(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
paint = new Paint();
}
public void onDraw(Canvas canvas){
paint.setColor(Color.WHITE);
canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
paint.setColor(Color.BLACK);
for (int i=0; i<CantidadDeEsferas; i++) {
Random r = new Random();
alto = r.nextInt(canvas.getHeight());
ancho = r.nextInt(canvas.getWidth());
radio = r.nextInt(101 - 50) + 50;
canvas.drawCircle(ancho, alto, radio, paint);
run();
isItOK = true;
}
}
public void run(){
while (isItOK){
try
{
Thread.sleep(2000);
isItOK = false;
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}