0

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?

Nestor
  • 8,194
  • 7
  • 77
  • 156

2 Answers2

1

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

            }
          });
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77
1

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

Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
  • Thanks, it cured the 'dead' state. The problem has evolved now :) If I use fling, it also detects the touch, so both event is fired. I'd like to make it distinct. If I touch with a single tap, then select the item, else the fling wins. How could I do it? – Nestor Sep 18 '13 at 13:12
  • My listener is a SimpleOnGestureListener (CustomGestureListener extends GestureDetector.SimpleOnGestureListener). If I use this code, my item gets highlighted but not gets pushed: @Override public boolean onSingleTapConfirmed(MotionEvent event) { ListView listView=(ListView)((InfoActivity)context).findViewById(android.R.id.list); listView.onTouchEvent(event); return true; } – Nestor Sep 19 '13 at 09:16
  • It will be better to create a new question and state these new problems there with more detail. I will be more than happy to answer – Umer Farooq Sep 19 '13 at 11:08
  • Agreed, I was about to do that. – Nestor Sep 19 '13 at 11:15