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

  • Home
  • SEARCH
  • 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 8582819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:23:27+00:00 2026-06-11T21:23:27+00:00

I am developing an android app which tracks touch events for the whole application.

  • 0

I am developing an android app which tracks touch events for the whole application. For that purpose, I want to override onTouchEvent() without an activity; i.e., inside a simple Java class, I don’t whether it’s possible. Any ideas are welcome.

  • 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-11T21:23:28+00:00Added an answer on June 11, 2026 at 9:23 pm

    No, you cannot arbitrarily override onTouchEvent, particularly in a “simple Java class”, i.e. one that does not extend a View.

    Solution 1

    If you want to capture all touches to your app, override onInterceptTouchEvent() in your main layout. So, if your main layout is a LinearLayout, do something like:

    public class MyTouchLayout extends LinearLayout {
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            // Do whatever with your touch event
            return false; // Do not prevent the rest of the layout from being touched
        }
    }
    

    Then, in your XML, you’d use:

    <com.example.MyTouchLayout
        ...
        >
    
        <!-- The rest of your layout -->
    
    </com.example.MyTouchLayout>
    

    Solution 2

    This is by far the simpler solution, though I’ve had varying luck with it in the past and would never suggest that you reply upon it.

    You can simply get the View that contains all your content (the root View, a LinearLayout above), then give it a listener.

    View v = findViewById(android.R.id.content); // Find the root View; you may have to give it your own ID in the XML, and use that
    v.setOnTouchListener(new OnTouchListener {
        // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an android app in which i want to send (name,email, cell
I'm currently developing an Android app, which loads events from a server using JSON
I am developing an Android app in which the application can be used by
I am developing an android app in which I want to find the latitude
I am developing an android app which needs to activate the GPS. I read
I am developing an Android app which gets an image encoded in base 64
I'm developing an Android app which is a quiz. On the other hand, I'm
I am developing an android app in which I have included a library project,
I am developing a basic android app which must handle several different things typically
I'm thinking about developing an iPhone/Android app which will include a server side. For

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.