FooBar
FooBar

Reputation: 105

How can I use canvas outside the onDraw method?

I need to draw something on the same canvas that onDraw() get access to.

This works fine as long as I am inside OnDraw(), but I don't know how to get that canvas when I'm outside.

Thanks for any suggestions.

@Override
protected void onDraw(Canvas canvas) {
    canvas.doSomething  // works fine
}

//new method to draw omething on the same canvas
mydraw(how to get canvas in here?){}

Upvotes: 2

Views: 1709

Answers (2)

gian1200
gian1200

Reputation: 3854

You can try to send canvas to your own method:

@Override
protected void onDraw(Canvas canvas) {
    yourMethod(canvas);
}

void yourMethod(Canvas canvas){
    //TODO
    //your code goes here
}

Upvotes: 2

gheese
gheese

Reputation: 1200

onDraw is called by the system, you should call do your drawing in there you could always pass he Canvas as a parameter to your myDraw method

Upvotes: 2

Related Questions