Question

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?

Was it helpful?

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().

OTHER TIPS

Try this way

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)
            {
              return gestureDetector.onTouchEvent(event); //UPDATE HERE

            }
          });
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top