I want to draw something repetitivelely each 100 milliseconds or when a button is pressed. For the button onclick event it works right, but I can't make it work in a thread. Following is the code:
onclick
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Draw();
}
});
thread
private Handler handler = new Handler();
private Runnable runnable = new Runnable()
{
public void run()
{
Draw();
handler.postDelayed(this, 1000);
}
};
Draw method
private void Draw(){
Paint paint = new Paint();
int i;
Canvas canvas = holder.lockCanvas();
// Dibujo el fondo
paint.setColor(getResources().getColor(android.R.color.black));
canvas.drawRect(0, 0, canvas.getWidth(), canvas.getHeight(), paint);
holder.unlockCanvasAndPost(canvas);
}