I think that you cannot use onDraw in the class, expanding the action due to the use of Canvas, you need to create a Custom component that extends some kind, and there you perform the actions, and what you need to do is =>
1. Extend an existing class or subclass of a class with its own class.
2. Return some of the methods from the superclass. Superclass methods for overriding begin with "on", for example, onDraw (), onMeasure (), onKeyDown (). This is similar to the βeventsβ in an Activity that you redefine for the life cycle and other functional hooks.
3. Use the new extension class. After completing your new class, extensions can be used instead of the view on which it was based.
Android
source share