How to add Id to canvas on Android?

0

I need to add a circle around the canvas every time I click a button (behavior identical to Windows Paint). But to move the circle clicked on the screen I need an ID. Anyone have any idea where I can add this ID? Thank you in advance.

    
asked by anonymous 23.08.2017 / 16:41

1 answer

1

The easiest way to do this is to create a Custom View . Not to mention that this will probably prevent boilerplate in your code.

private class CircleCanvas extends View {

    public CircleCanvas(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        ...
        createCircle(...)
    }

}

And when you create the circle in your code, use the method View#setId() .

CircleCanvas circle = new CircleCanvas(ctx);
circle.setId(CIRCLE_ID);
    
23.08.2017 / 17:23