1

I want to redraw a view from another method (say setProgress) in a class extending View. How can I do this.

My view class is

public class SpinView extends View {
    private Paint paint;
    private Context context;
    private Canvas canvas;
    private RectF arcOval;

    public SpinView(Context context) {
        super(context);
        this.context = context;

    }
    public SpinView(Context context, AttributeSet attrs) {
        super(context, attrs, 0);
        this.context = context;
    }

    public SpinView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        this.canvas = canvas;
        Display d = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        int width = d.getWidth();
        int height = d.getHeight();
        arcOval = new RectF((width/2-50), (height/2-50), (width/2+50), (height/2+50));
//      RectF arcOval = new RectF(200, 200, 300, 300);
        paint = new Paint();
        paint.setColor(Color.BLUE);
        paint.setStrokeWidth(10);
        paint.setAntiAlias(true);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.STROKE);

        canvas.drawArc(arcOval, 270f, 360, false, paint);
    }

    protected void setProgress(float angle){
        paint = new Paint();
        paint.setColor(Color.YELLOW);
        paint.setStrokeWidth(10);
        paint.setAntiAlias(true);
        paint.setStrokeCap(Paint.Cap.ROUND);
        paint.setStyle(Paint.Style.STROKE);

        canvas.drawArc(arcOval, 270f, angle, false, paint);
    }

}

All I want is to draw a circular arc of yellow color over the initially created arc of Blue color. Any help?

donison24x7
  • 304
  • 1
  • 15

1 Answers1

0

You can use invalidate() method to call ondraw again

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
Sihat Afnan
  • 742
  • 7
  • 14