Reputation: 4395
My SurfaceView's onDraw method draw's a LinkedList of paths determined by TouchEvents on the screen. I want add an undo feature that removes the last path node from the LinkedList. When the button is hit, the path is removed from the list but the SurfaceView doesn't update until I either hit the undo button again or touch the screen.
Thanks, Eric
Upvotes: 4
Views: 2746
Reputation: 13855
OnDraw is called every 60 ms in a thread but it isn't updating there which confuses me.
you should be using:
postInvalidate();
not
invalidate();
postInvalidate();
tells the main UI thread to redraw on its next convenient time. The way you are doing it will not work on a seperate thread.
Upvotes: 3
Reputation: 429
That's because Views are only updated when onDraw() is called, which happens due to screen activity (like you touching it) or when it's programatically forced to do so.
You want to force it: use the invalidate() method inherited from View.
If the removal happens inside you SurfaceView, just write invalidate() AFTER you're done removing. If it happens outside, then just do surfaceViewInstance.invalidate().
Hope this helps
Upvotes: 0