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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:53:33+00:00 2026-06-06T10:53:33+00:00

I am trying to separate a few things in here. I have a program

  • 0

I am trying to separate a few things in here.

I have a program with Imagebuttons. They have onTouchListeners attached to them.

I wish touch event to be fired JUST with a touch, not with a click. I mean, if I use a mouse to click, for example, I don’t want the onTouch event attached to the ImageButton to be fired. However it IS fired when you click the mouse over the button.

Is it possible to fire the event JUST when a touch happens?

My code:

myImageButton.setOnTouchListener(new Button.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent arg1) {
                 if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN) {    
                    Toast.makeText(LiVoiceActivity.this,
                                    "You touched me!",
                                    Toast.LENGTH_LONG).show();
                }
                 return true;
            }
    });

Thank you!

  • 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-06T10:53:35+00:00Added an answer on June 6, 2026 at 10:53 am

    There’s a field known as a Tool_Type in the MotionEvent class. I have implemented a check for the mouse type here:

    API 14 AKA EASY MODE

    myImageButton.setOnTouchListener(new Button.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent arg1) {
                         if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN
                                  && (MotionEvent.TOOL_TYPE_MOUSE != arg1.getToolType(0)) {    
                            Toast.makeText(LiVoiceActivity.this,
                                            "You touched me!",
                                            Toast.LENGTH_LONG).show();
                        }
                         return true;
                    }
            });
    

    API 9

    myImageButton.setOnTouchListener(new Button.OnTouchListener() {
                    @Override
                    public boolean onTouch(View v, MotionEvent arg1) {
                         if (arg1.getAction() == android.view.MotionEvent.ACTION_DOWN
                                  && (arg1.getSize() > 1) {    
                            Toast.makeText(LiVoiceActivity.this,
                                            "You touched me!",
                                            Toast.LENGTH_LONG).show();
                        }
                         return true;
                    }
            });
    

    Now this checks the size of the MotionEvent received. PRESUMABLY, a mouse click would have a size of 1, therefore, only recognize sizes bigger than 1. Play around with that number and see if you can differentiate between the mouse and finger touch.

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

Sidebar

Related Questions

What I am trying to accomplish here is to separate a firstname, lastname combo
I'm trying to optimize my website. I have a few plugins to include (jquery
I need to do a few db things and I would rather have extension
I am only a few days in and have only made a couple things
Let me first of all clarify a few things: I am not trying to
I have few jquery tabs on a usercontrol that loads a separate user control
I have a few basic questions about sockets programming. I am trying to write
I have a few scripts that need to run concurrently as separate processes. My
I have a few apps that I am trying to develop a reusable URL
I have got a few tables which I am trying to join. I just

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.