Search code examples
androidandroid-listviewgestureonfling

ListView stopped accepting basic gestures after setting custom GestureListener


I have created a GestureListener with a customized onFling method. I didn't override onScroll or onSingleTapConfirmed.

I created the listener like this:

   ListView listView=(ListView)findViewById(android.R.id.list);
        final GestureDetector gestureDetector = new GestureDetector(new CustomGestureListener(this));
        if (listView != null)
          listView.setOnTouchListener(new View.OnTouchListener()
          {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
              if (gestureDetector.onTouchEvent(event))
              {
                return false;
              }
              return true;
            }
          });

After that, the onFling event works fine but the single touch and scroll events are gone, my listview is dead. What should I set?


Solution

  • Change to this:

            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
              return gestureDetector.onTouchEvent(event);
            }
    

    For your second problem, use SimpleOnGestureListener. It has the methods that you want onSingleTapConfirmed() & onFling().