user1783960
user1783960

Reputation: 51

canvas not redrawing correctly

I am writing a simple view that will show a dot, after some action, show the next dot. The dots are on a vertical strip. so I create a function that'll clear the strip. then draw a circle at the position where I want the dot. the code segment is as followed.

private void clear_strip(){
    paint.setColor(Color.BLACK);
    paint.setStyle(Paint.Style.FILL_AND_STROKE);
    m_canvas.drawRect( 0, 0,width/8, height, paint);
    paint.setColor(Color.GREEN);
}

private void set_dot(){
    clear_strip();
    m_canvas.drawCircle(width/10, (int) (font_height*(scoreboard.current_batter_position()+0.5))/1, font_height/4, paint);
}

@Override
protected void onDraw(Canvas canvas) {
    set_dot();
    canvas.drawBitmap(m_bitmap, 0, 0, paint);
}

but one of the dot is just not updating. It'll keep the old dot, skip that dot, then move to the next dot. I tried to print out the position to logcat right before the drawCircle call, and the position is right, it's just not drawing (and not clearing as well)....please advise.

Upvotes: 1

Views: 105

Answers (1)

Henry
Henry

Reputation: 43738

You get a canvas to draw into passed into your onDraw method. But the point drawing code uses the canvas m_canvas. Pass the canvas as a parameter to your dot drawing code to fix that.

Upvotes: 1

Related Questions