As a beginner, I'm trying to create a simple drawing application in android. However, I keep running into the following issue where I am not able to press any of my buttons because a path is drawn on top of the button. How would I adjust the following code so that the ability to draw is separated from pressing buttons?
I am definitely also open to suggestions on how to decouple the drawing experience from the button clicking experience, but I am more interested in how to resolve the issue with the code I currently have as a learning experience.
To give you a better example of what I mean is : http://imgur.com/8i1RCt7
Simplified Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
aButton = (Button) findViewById(....
bButton = (Button) findViewById(....
aListener = new OnClickListener(){...
bListener = new OnClickListener(){...
nextButton.setOnClickListener(aListener);
clearButton.setOnClickListener(bListener);
layout = (RelativeLayout) findViewById(R.id.activity_main);
cView = new CanvasView(this);
layout.addView(cView);
listener = new OnTouchListener(){
@Override
public boolean onTouch(View arg0, MotionEvent event) {
float posX = event.getX();
float posY = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
path.moveTo(posX, posY);
break;
case MotionEvent.ACTION_MOVE:
case MotionEvent.ACTION_UP:
path.lineTo(posX, posY);
break;
} // ends switch statement
cView.invalidate();
return true;
}
};
cView.setOnTouchListener(listener);