warci
warci

Reputation: 123

How can I redraw a View after a TouchEvent?

I subclassed View to get an View on which the user can "draw" with his fingers. I implemented the Interface View.OnTouchListener.

How can I trigger within the onTouch method the redraw of the View? Do I need to implement a Thread / Runnable? I thought that invalidate() triggers the redraw, but this doesn't work.

Upvotes: 0

Views: 1813

Answers (1)

J. Maes
J. Maes

Reputation: 6892

Just call this.invalidate in the onTouchEvent method of your view, it really should work unless you're not doing the proper thing in your onDraw method. Make sure you're referencing to the right canvas an draw the thing in your overridden onDraw method instead of for example the constructor.

@Override
public boolean onTouchEvent(MotionEvent event) {
    this.invalidate();
    return true;
}

Upvotes: 1

Related Questions