MotionEvent doesn’t get a constructor, I wanted to manually create a MotionEvent in my unit test, then how to get that? Thanks.
MotionEvent doesn’t get a constructor, I wanted to manually create a MotionEvent in my
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should use one of the static
obtainmethods of theMotionEventclass to create a new event.The simplest way (besides wrapping a new event from an existing one) is:
API Docs:
Parameters:
downTimeThe time (in ms) when theuser originally pressed down to start
a stream of position events. This
must be obtained from
SystemClock.uptimeMillis().
eventTimeThe the time (in ms) whenthis specific event was generated.
This must be obtained from
SystemClock.uptimeMillis().actionThe kind of action beingperformed — one of either
ACTION_DOWN,ACTION_MOVE,ACTION_UP, orACTION_CANCEL.xThe X coordinate of this event.yThe Y coordinate of this event.metaStateThe state of any meta /modifier keys that were in effect
when the event was generated.
Link to API Docs