0

I'm using RecylerView in my Android app, for each row, I used 1 line for Text and 1 line for containing 3 buttons. The problem is: if I hold the position in the region of buttons and drag UP/DOWN, RecylerView does not scroll. But if I hold and drag other positions (Not in region of buttons), It scrolls normally.

public static boolean inRegion(float x, float y, View v) {
        int[] location = new int[8];
        v.getLocationOnScreen(location);
        return location[0] + v.getWidth() > x && location[1] + v.getHeight() > y 
                && location[0] < x && location[1] < y;
    }

 public static View getMapView(ViewGroup viewGroup) {
        View mapView = null;
        int size = viewGroup.getChildCount();
        for (int i = 0; i < size; i++) {
            View view = viewGroup.getChildAt(i) ;
            if (view.getTag() != null && view.getTag() instanceof String) {
                String tag = (String) view.getTag();
                if (tag.equals("MapView"))
                    return view;
            }
            if (view instanceof ViewGroup) {
                mapView = getMapView((ViewGroup) view);
                if (mapView != null)
                    break;
            }

        }
        return mapView;
    }

  @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        long start = System.currentTimeMillis();
        View view = getMapView(this);
        boolean r = false;
        if (view != null) {
            r = inRegion(event.getRawX(), event.getRawY(), view);
        }
        if (r == false)
            return super.onInterceptHoverEvent(event);
        else
            return false;
    }

How can I fix this?

Toan Tran Van
  • 695
  • 1
  • 7
  • 25

1 Answers1

1

I'm guessing you modified the behavior of the buttons' touch listeners. Remove that and your RecyclerView should work fine.

josephus
  • 8,284
  • 1
  • 37
  • 57
  • Could you please give me more details? Because I just us onClick listener for these button – Toan Tran Van Dec 15 '14 at 02:38
  • I'm so sorry, source code relates to our team's project, Not my personal project :| – Toan Tran Van Dec 15 '14 at 03:12
  • you don't have to show anything specific to the business, just the part that doesn't work. you can mask off anything that would potentially show what the app is about. – josephus Dec 15 '14 at 03:41
  • After debugging, I found that this issue happens because I used onInterceptTouchEvent(). I added source code in my question, please check! – Toan Tran Van Dec 15 '14 at 04:11
  • why do you need to override this? – josephus Dec 15 '14 at 04:26
  • I do this to make sure it will not perform any action if users click on each row and require users to click 1 of 3 buttons instead – Toan Tran Van Dec 15 '14 at 04:29
  • you're returning `super.onInterceptHoverEvent(event)`, try just the regular old `onInterceptTouchEvent`. Also, try returning the super call instead of false. – josephus Dec 15 '14 at 05:57
  • there's a very good read [here](http://stackoverflow.com/a/22490810/611228) that talks about modifying android touch event – josephus Dec 15 '14 at 06:05