I am learning Android and java so this is probably an easy question.
I am trying to call invalidate() on my DrawView. I have read up on it and I think the problem is that I cannot call invalidate outside of the UI thread (or something). As far as I know I only have one thread running as this is a simple TicTacToe game. so here is my code.
DrawView dv;
Create the dv object to associate it with the DrawView class
dv.invalidate();
trying to call the invalidate method.
This is the first part of my DrawView class
class DrawView extends View implements OnTouchListener, OnGestureListener
{
public DrawView(Context context)
{
super(context);
this.setOnTouchListener(this);
}
@Override
protected void onDraw(Canvas canvas)
{
canvas.drawColor(0xFF303030);
Paint paint = new Paint();
paint.setColor(0xFFFFFFFF);
board.draw(canvas);
detectEnd();
}
it seems as if invalidate IS called however it crashes the program. Any ideas?
EDIT: I tried dv.postInvalidate()however it throws a null pointer exception. I have tried to initialize the DrawView dv in several ways but to no avail.
If you are calling invalidate from outside the DrawView, you have to call postInvalidate() instead.
Also, it generally isn’t ever a good idea to play sounds during the onDraw method.