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 9062159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:40:07+00:00 2026-06-16T15:40:07+00:00

Using myObject.performClick() I can simulate click event from the code. Does something like this

  • 0

Using myObject.performClick() I can simulate click event from the code.

Does something like this exist for onTouch event? Can I mimic touch action from the Java code?

EDIT

This is my onTouch listener.

   myObject.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            // do something
            return false;
        }
    });
  • 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-06-16T15:40:08+00:00Added an answer on June 16, 2026 at 3:40 pm

    This should work, found here: How to simulate a touch event in Android?:

    // Obtain MotionEvent object
    long downTime = SystemClock.uptimeMillis();
    long eventTime = SystemClock.uptimeMillis() + 100;
    float x = 0.0f;
    float y = 0.0f;
    // List of meta states found here: developer.android.com/reference/android/view/KeyEvent.html#getMetaState()
    int metaState = 0;
    MotionEvent motionEvent = MotionEvent.obtain(
        downTime, 
        eventTime, 
        MotionEvent.ACTION_UP, 
        x, 
        y, 
        metaState
    );
    
    // Dispatch touch event to view
    view.dispatchTouchEvent(motionEvent);
    

    For more on obtaining a MotionEvent object, here is an excellent answer: Android: How to create a MotionEvent?

    EDIT: and to get the location of your view, for the x and y coordinates, use:

    int[] coords = new int[2];
    myView.getLocationOnScreen(coords);
    int x = coords[0];
    int y = coords[1];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read that a using like this: using (myObject) { myObject.DoStuff(); } Can
When using XML serialization in C#, I use code like this: public MyObject LoadData()
I would like to update all properties from MyObject to another using Reflection. The
What I want to do is something like this: switch( myObject.GetType().GetProperty( id) ) {
In Eclipse if you have a method: String MyObject.getValue(); When using this you can
Using instance methods as callbacks for event handlers changes the scope of this from
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
I'm using $.grep() to pull back a set of JSON results like so: myObject.appJSON
Using this code : import org.codehaus.jackson.map.ObjectMapper; ObjectMapper objectMapper = new ObjectMapper(); String str =
Using a DataModel<MyObject> , I fill a data table according to this response Now

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.