public boolean onTouchEvent(MotionEvent e)
{
int xpos=(int) e.getX();
int ypos=(int) e.getY();
switch (e.getAction())
{
case MotionEvent.ACTION_DOWN:
Log.d("DEBUG", "On touch (down)" + String.valueOf(xpos) + String.valueOf(ypos));
case MotionEvent.ACTION_UP:
Log.d("DEBUG", "On touch (up)" + String.valueOf(xpos) + String.valueOf(ypos));
case MotionEvent.ACTION_MOVE:
Log.d("DEBUG", "On touch (move)" + String.valueOf(xpos) + String.valueOf(ypos));
break;
}
return true;
}
Then override the draw method
@Override
public void draw(Canvas canvas) {
super.draw(canvas);
}
So you try
canvas.drawLine(startX, startY, stopX, stopY, paint);
To make a line go straight up try
canvas.drawLine(xpos, ypos, xpos, getHeight() , new Paint());
Get height should be your screen's height (Since your drawing a line straight up)
For this the variables xpos and ypos should be available to all methods so add
int xpos,ypos = 0;
To the the top of your code (but within the class declaration)
For drawling a between the circles you would need to get the first circles x,y position on touch then set the drawLine method with them, so something like:
currentCircleXpos, lastCircleXpos = 0; //you would set these in the onDraw method when the circle get's drawn.
currentCircleYpos, lastCircleypos = 0;
canvas.drawLine(currentCircleXpos, currentCircleYpos, lastCircleXpos, lastCircleYpos , new Paint());
OnDraw() method-------
for (int y = 0; y < rows; y++)
{
for (int x = 0; x < cols; x++)
{
canvas.drawCircle((x + 1) * xStep, (y + 1) * yStep, 20, pDot);
currentCircleXpos = x;
currentCircleYpos = y; //gets the circle that is being drawn's location
if (y == 0)
{
//canvas.drawLine((x + 1) * xStep, yStep, (x + 1) * xStep, rows * yStep, pDot);
}
}
//canvas.drawLine(xStep, (y + 1) * yStep, cols * xStep, (y + 1) * yStep, pDot);
}