I am trying to program an androd application where if there is input on two places of the screen in sucsession then it will draw a line between the two points. I have already set up “X” and “Y” values that work and columns and rows are defined by the “X” and “Y” values. After those i have an IF statement that needs to draw a line between the two points. Say if column one and row two are selected and then colum one and row three are selcted I want a line to be drawn between the two points. Also I am not totally sure how to use the MotionEvent stuff or how to put the touch actions into the IF statement.
final View touchView = findViewById(R.id.touchView);
touchView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
String.valueOf(event.getX() + String.valueOf(event.getY()));
double c = event.getX();
double column = Math.floor(event.getX()/(480/12));
double r = event.getY();
double row = Math.floor(event.getY()/(630/12));
if (column == 0 && row == 2 //there should be more stuff here
) {
//I dont know how to draw a line in here, please help
}
return true;
}
});
}
Rather than explain the details here, I’ll point you to these pieces of sample code from the
ApiDemossample project that comes with the SDK, that probably do exactly what you want:The basic idea is to store X and Y coordinates in your touch event handler, invalidate the
View, and then draw the lines in theonDrawmethod usingCanvasoperations such asdrawLine.