Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4589568
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:05:48+00:00 2026-05-21T22:05:48+00:00

MotionEvent doesn’t get a constructor, I wanted to manually create a MotionEvent in my

  • 0

MotionEvent doesn’t get a constructor, I wanted to manually create a MotionEvent in my unit test, then how to get that? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T22:05:49+00:00Added an answer on May 21, 2026 at 10:05 pm

    You should use one of the static obtain methods of the MotionEvent class to create a new event.

    The simplest way (besides wrapping a new event from an existing one) is:

    static public MotionEvent obtain(long downTime, long eventTime, int action,
            float x, float y, int metaState) {
    

    API Docs:

    Create a new MotionEvent, filling in a
    subset of the basic motion values.
    Those not specified here are: device
    id (always 0), pressure and size
    (always 1), x and y precision (always
    1), and edgeFlags (always 0).

    Parameters:

    • downTime The time (in ms) when the
      user originally pressed down to start
      a stream of position events. This
      must be obtained from
      SystemClock.uptimeMillis().
    • eventTime The the time (in ms) when
      this specific event was generated.
      This must be obtained from
      SystemClock.uptimeMillis().
    • action The kind of action being
      performed — one of either
      ACTION_DOWN, ACTION_MOVE,
      ACTION_UP, or ACTION_CANCEL.
    • x The X coordinate of this event.
    • y The Y coordinate of this event.
    • metaState The state of any meta /
      modifier keys that were in effect
      when the event was generated.

    Link to API Docs

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on MotionEvent by which i can get different - different gesture
Can I get the value of MotionEvent.getRawX()/getRawY() of other pointers ? MotionEvent.getRawX() api reference
I have an instrumentation that I want to use to test my application, but
My TextView does not support the MotionEvent.Action_UP. I only get 0 on event.getAction. But
I have a small test app on Android that is meant to test tracking
I have a Gridview displaying buttons that get their content from an array, I
I am having trouble getting my activity to generate a MotionEvent.ACTION_UP. Probably a beginner's
I just cant get this working. I tried using the code below with onTouchEventand
I have a custom ViewGroup (blue background) that when touched sometime during the app's
Is there a way to detect a click from MotionEvent s in Android? To

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.