I am quite new to Android programming and Java (though I have some experience with C#, so that helps).
At this moment I'm goofing around with a couple of things to get to know how everything works. I've made an activity which implements onTouchListener. I've overridden onTouch and have a switch on event.getAction():
public boolean onTouch(View v, MotionEvent event)
{
float x;
float y;
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN: // gets called
{
x = event.getX();
y = event.getY();
circle c = new circle(this, x, y, 10, 0xFFFFFF);
_main.addView(c, tapCount++);
break;
}
case MotionEvent.ACTION_MOVE: // doesnt seem to do anything
{
x = event.getX();
y = event.getY();
circle c = new circle(this, x, y, 10, 0xFFFFFF);
_main.addView(c, tapCount++);
break;
}
}
return false;
}
Where "circle" is a class which draws a circle.
What I expected to see was a trail of circles as I dragged my finger over the screen. In stead, the circle is only being drawn when I start touching.
I have compared my code to examples (for example: this blogpost by Google: http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html ) and I can't find my mistake.
EDIT: Link to the full class: http://pastebin.com/tVDQjQhu
EDIT: Fixed. One has to return true in the onTouch() function. d'oh!
I was having the same problem while using MotionEvent.ACTION_MOVE
.
For MotionEvent.ACTION_MOVE
to work, return true instead of false.
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