I have make application in which swipe Gesture detection is used for left to right & right to left.
I got success with 2.2 AVD emulator, but when I try to use same code in tablet 3.0 it not working
Please tell me whats wrong.
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private class GestureListener extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(RssActivity.this, "Right to left",
Toast.LENGTH_LONG).show();
SetNewRightclickActivity();
Log.i(TAG, "Right to left");
return true; // Right to left
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Toast.makeText(RssActivity.this, "Left to right",
Toast.LENGTH_LONG).show();
Log.i(TAG, "Left to right");
SetNewLeftclickActivity();
return true; // Left to right
}
if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return true; // Bottom to top
} else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE
&& Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
return true; // Top to bottom
}
return false;
}
}
Main::
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.rssheader);
gestureDetector = new GestureDetector(new GestureListener());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
};
You need to set
gestureListener(in onCreate method) to a view on which you want to detect swipes.Set id to a view/viewgroup in your layout in rssheader.xml, for example:
now fetch that id in Activity class and set listener to it