0

Here is a summary of what i m trying to achieve. I have a view, on that view i m listening for MotionEvent. When it matches a specific condition, i would like to pass that MotionEvent to a GridView, in order to scroll. I m doing something like

if (event.getAction() == MotionEvent.ACTION_MOVE) {
    if (condition match) {
        getGridView().dispatchTouchEvent(event);
    }
}

But it does not make my grid scrolling according to the MotionEvent. Maybe it's not listening for that kind of event but since there is not "ScrollEvent" i don't know.

Can anyone please enlight me about that. I didn't find the doc helpfull. Thank you.

Mostrapotski
  • 425
  • 3
  • 11

2 Answers2

0

In order to process motion events a view needs to get the full set of events related to that movement.

For example, a scroll should start with MotionEvent.ACTION_DOWN , followed by several MotionEvent.ACTION_MOVE and finalized with a MotionEvent.ACTION_UP. You can't just dispatch one of these events, the full set need to be dispatched for the view to be able to decode the scroll movement.

Regards.

Luis
  • 11,978
  • 3
  • 27
  • 35
0

Luis have explained the reason why your grid view doesn't scroll. In fact such dispatch is not correct. You said that you want to pass the MotionEvent of View A to View B. But the x and y in a motion is relative to the view, and cannot be used directly in another view. Try to look the source code of ViewGroup.dispatchTouchEvent(), ViewGroup will transform a motion before it is dispatched to a child. If View B is a child of View A, you should use onInterceptTouchEvent() to intercept the motion , instead of changing the dispatch mechanism.

faylon
  • 7,360
  • 1
  • 30
  • 28
  • Thank you guys for the answer. For the one who -1ed the question, i did search. For my information and to increase my questionning skills for the next time, you can explain why you -1ed. The question is clear, i just took a wrong approach, and since it's not correct, i couldn't find tips to achieve what i want. – Mostrapotski Dec 13 '12 at 08:04