Mike G
Mike G

Reputation: 4959

How does a motion event gets associated with a certain view?

How does a motion event gets associated with a certain view? is It the window manager, phone manager or view class? I am facing a problem which is: i am sending motionEvents using sendPointerSync from instrumentation class i can see the events being consumed in my log but i cant see the interaction on my emulator window.

Upvotes: 0

Views: 94

Answers (1)

Alexis Andre
Alexis Andre

Reputation: 141

You implement the OnTouchListener interface in YourViewClass then you setOnTouchListener(yourViewInstance).

Then you'll get the MotionEvents in the onTouch method.

Edit

From what I understand, the window manager dispatches the events to the views in the following way. When you touch something, it sends the event to the view that is responsible for drawing this part. As stated in the docs http://developer.android.com/guide/topics/ui/ui-events.html the

These methods are called by the Android framework when the respective action occurs on that object. For instance, when a View (such as a Button) is touched, the onTouchEvent() method is called on that object.

Using instrumentation, you'll send the events to the activity you want to test, and the events are dispatched according to the view layout. Of course, you'll need to register the interfaces for the views to catch the events.

I apologize if that is not what you were looking for.

Upvotes: 1

Related Questions