Question

Trying to determine why the onDraw is not getting called always. I have following code in onTouch event of a custom view class.

public boolean onTouch(View view, MotionEvent event) {
 <<do something>><
 switch (eventType) {
        case MotionEvent.ACTION_DOWN: 
           <<do something>>
        case MotionEvent.ACTION_MOVE: 
           <<do something>>
            Log.d(TAG, "calling invalidate"); 
            invalidate();
            break;
 }
}

The logs show the following statement "calling invalidate" but the ondraw is not ALWAYS called after this log statement. It is almost like batching the invalidates and calling the onDraw once every X times.

thanks in advance

Was it helpful?

Solution

Yes that is what invalidate() does; it marks the current state of the View as out of date, and schedules a call to draw() to be run on the next drawing iteration, which will be at some point after the current events scheduled on the main Thread (e.g. handling user interaction) are completed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top