Android onFling not responding
Posted
by
Kevin Moore
on Stack Overflow
See other posts from Stack Overflow
or by Kevin Moore
Published on 2010-12-23T21:34:24Z
Indexed on
2012/07/05
3:16 UTC
Read the original article
Hit count: 156
android
I am new to android first of all so think of any newbie mistakes first
I am trying to add a fling function in my code.
public class MainGamePanel extends SurfaceView implements
SurfaceHolder.Callback, OnGestureListener {
private MainThread thread;
private Droid droid;
private Droid droid2;
private static final String TAG = gameView.class.getSimpleName();
private GestureDetector gestureScanner;
public MainGamePanel(Context context){
super(context);
getHolder().addCallback(this);
droid = new Droid(BitmapFactory.decodeResource(getResources(), R.drawable.playerbox2), 270, 300);
droid2 = new Droid(BitmapFactory.decodeResource(getResources(), R.drawable.playerbox2), 50, 300);
thread = new MainThread(getHolder(), this);
setFocusable(true);
gestureScanner = new GestureDetector(this);
}
public boolean onTouchEvent(MotionEvent event){
return gestureScanner.onTouchEvent(event);
}
@Override
protected void onDraw(Canvas canvas){
canvas.drawColor(Color.BLACK);
droid.draw(canvas);
droid2.draw(canvas);
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
{
droid.setX(50);
droid.setY(50);
Log.d(TAG, "Coords: x=" + e1.getX() + ",y=" + e2.getY());
return true;
}
@Override
public boolean onDown(MotionEvent e) {
droid2.setX((int)e.getX());
droid2.setY((int)e.getY());
Log.d(TAG, "Coords: x=" + e.getX() + ",y=" + e.getY());
return false;
}
I got the gestureListener to work with: onDown, onLongPress, and onShowPress.
But i can't get any response with onFling, onSingleTapUp, and onScroll.
What mistake am I making? does it have to do with views?
I don't know what code would be useful to see.... so any suggestions would be much appreciated. Thank You!
© Stack Overflow or respective owner