I have an Activity that implements a gesture detector to catch a user input to go to other screens. This works fine, but - I recently updated a class that comes from BaseActivity to add an onClick function, and now that the click event seems to block onFling from getting hit. OnClick is tied to the TextView area (in LinearLayout) that I have on my screen. The resultsClick method is connected to the TextView using its onClick property in the XML layout.
I tried changing the return values ββin onSingleTapUp and onDown with no luck. I also tried adding log entries to all the functions below. None of them work when I rush into the TextView area, but they work in other areas of the screen.
Perhaps I am using the wrong search terms, but I could not find an example that appealed to this, but I am sure that this problem was solved earlier.
public class DerivedActivity extends BaseActivity { ... public void resultsClick(View v) { try { Log.i(this.toString(), "resultsClick"); startActivity(new Intent(this, Results_TabHost.class )); } catch (Exception e) { Log.e(this.toString(), "Exception" + e.toString()); } }
Here is a base class implementing GestureListener code
public class BaseActivity extends ActivityGroup implements OnGestureListener { ... private static final int SWIPE_MIN_DISTANCE = 120; private static final int SWIPE_MAX_OFF_PATH = 250; private static final int SWIPE_THRESHOLD_VELOCITY = 200; public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { try { Log.i(this.toString(), "onFling"); // jump right out if not a swipe/fling if (Math.abs( e1.getY() - e2.getY() ) > SWIPE_MAX_OFF_PATH) { return false; } // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY ) { Log.i(this.toString(), "fling left"); rightArrowClick(null); } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY ) { Log.i(this.toString(), "fling right"); leftArrowClick(null); } } catch (Exception e) { Log.e(this.toString(), "Exception" + e.toString()); } return true; }// end onFling // These next methods we are required to have - even if unused - // in order for the Gesture Handling to work @Override public boolean onTouchEvent(MotionEvent motionEvent) { return this.gestureDetector.onTouchEvent(motionEvent); } @Override public void onLongPress(MotionEvent e) { // Intentionally not handling - must be overridden by listener class } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // Intentionally not handling - must be overridden by listener class // Intentionally returning true - per code examples return true; } @Override public void onShowPress(MotionEvent e) { // Intentionally not handling - must be overridden by listener class } @Override public boolean onSingleTapUp(MotionEvent e) { // Intentionally not handling - must be overridden by listener class // Intentionally returning true - per code examples return true; } @Override public boolean onDown(MotionEvent e) { // Intentionally not handling - must be overridden by listener class // Intentionally returning true - per code examples return true; } ... }
android android-activity onclick gesture-recognition
bursk
source share