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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:13:10+00:00 2026-05-26T02:13:10+00:00

I am trying to identify UI-control that fired MotionEvent in Android. I have one

  • 0

I am trying to identify UI-control that fired MotionEvent in Android. I have one doubleTapDetector

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main); 
    doubleTapDetector = new GestureDetector(this, new DoubleTapDetector());
}

declared as

private class DoubleTapDetector extends GestureDetector.SimpleOnGestureListener {     
    @Override
     public boolean onDoubleTap(MotionEvent e) {
        String uiControlName = obtainUiControlName(e);
        // Do something depends on uiControlName
        return true;
    }        

    private String obtainUiControlName(MotionEvent e) {
        int deviceId = e.getDeviceId();
        switch (deviceId) {
            case R.id.button1: return "Button1"; 
            case R.id.button2: return "Button2";  
        } 
        return null;
    }         
} 

placed on both buttons

Button button1 = (Button) findViewById(R.id.button1);
    outcomeButton.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            doubleTapDetector.onTouchEvent(event);
            return true;
        }
    });        

Button button2 = (Button) findViewById(R.id.button2);
    outcomeButton.setOnTouchListener(new OnTouchListener(){

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            doubleTapDetector.onTouchEvent(event);
            return true;
        }
    });

The problem is that deviceId always equals 0 and I can’t identify which button fires double click event. Is there a way to do that without implementing of two different doubleTapDetector’s for each button?

  • 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-26T02:13:10+00:00Added an answer on May 26, 2026 at 2:13 am

    Mistake. getDeviceId returns physical pointer device id from where touch was received. Not Widget ID.

    I feel that only way to do it is to create unique DoubleTapDetector for each your button, and also store some kind of button’s ID in your DoubleTapDetector class. Because onDoubleTap method doesn’t give enough info about Widget on which tap happened.

    Like this:

    private class DoubleTapDetector extends GestureDetector.SimpleOnGestureListener { 
       int id;
       DoubleTapDetector(int id){
          this.id = id;
       }
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to identify all the nodes in a tree that lead to
I am trying to identify SQL INSERTS that occur when a record is viewed
I have a partial view (user control) that is shared by my Create and
I'm trying to identify the scanners attached to the computer. One of the possible
I'm trying to identify an empty element that might or might not contain a
I have a Silverlight application that I am trying to style. This style simply
I'm trying to identify the Navigation Bar in the current view so that I
I am trying to identify all the <UL> that contain a menu list by
I'm trying to identify which OSX application is currently active. I understand that in
I'm trying to identify street corners in a free text. I have a list

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.