I got a View and want to update it every time a new line object is stored in my lines array. This happens at drawLine(). Therefore drawYourselfe() should somehow force onDraw() and wait till its done. Here is a part of my code. Can anyone tell me how drawYourselfe() should look?
public class MyView extends View{
private ArrayList<Line> lines;
private Paint paint; //created in constructor
protected void drawLine(float[] f)
{
if(f.length != 5)
{
} else {
lines.add(new Line(f));
Log.d("SuM","added Line");
if(!bufferedDrawing) // in this example bufferedDrawing=false because i want to update the View on every new Line;
{
drawYourselfe();
}
}
}
protected void onDraw(Canvas canvas) {
Log.d("SuM","onDraw");
for(Line l : lines)
{
l.analysis(); //Logs fromX,toX,fromY,toY and color to console
paint.setColor(l.getColor());
canvas.drawLine(l.getFromX(),l.getFromY(),l.getToX(),l.getToY(), paint);
}
}
public void drawYourselfe()
{
//When this is called, onDraw should be called and the Thread should wait till its done;
}
}
Edit: I better mention what I want to do and why just simply invalidate() doesnt work: In my MainActivity I call
myView.drawLine(line1);
myView.drawLine(line2);
myView.drawLine(line3);
//and so on...
and I want to see how these lines are drawn one after one. When calling invalidate() in drawYourselfe() I only see all lines drawn but not one after one. I know that these tree lines are drawn so fast that I cant see them drawn one by one, but in the app Im doing it with thousand of lines.
Call invalidate(), but there is no way to wait for the draw to complete. draw will be called later, after your drawLine call returns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With