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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T01:51:11+00:00 2026-05-15T01:51:11+00:00

In my app, when one particular image button is clicked and held, i must

  • 0

In my app, when one particular image button is clicked and held, i must be able to calculate the time for which the image button was held pressed. Can any one help me by giving some simple guidance or sample code. i am really stuck up here. Is there any specific event listener for this particular requirement. I am writing this app specifically for a touch screen phones only.

  • 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-15T01:51:11+00:00Added an answer on May 15, 2026 at 1:51 am

    What you want to use is this:

    OnTouchListener touchListener = new OnTouchListener(){
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            Log.d(LOG_TAG, "Action is: " + action);
    
            switch (action){
            case MotionEvent.ACTION_DOWN:
                timeAtDown = SystemClock.elapsedRealtime();
                break;
    
            case MotionEvent.ACTION_UP:
                long durationOfTouch = SystemClock.elapsedRealtime() - timeAtDown;
                Log.d(LOG_TAG, "Touch event lasted " + durationOfTouch + " milliseconds.");
                break;
            }
            return false;
        }
    
    };
    
    button.setOnTouchListener(touchListener);
    

    timeAtDown is a long defined as a class field, since it needs to persist between calls to the touchListener. Using this you don’t interfere with the button’s normal operation either; you can set a click listener which will function properly. Note: The ‘click’ operation doesn’t happen until the touch event’s action goes from DOWN (or MOVE) to UP.

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

Sidebar

Related Questions

When using the Scripting Bridge to access the Mail app one can easily retrieve
I have one app, a UIImage* . I'm painting the image twice: Once in
I am developing one app , which is required to integrate Google checkout.I am
I have one C code app. which i was building using MS-VS2005. I had
I'm getting this exception in my WPF app on one particular PC, on half
I'm developing a SWT app and in one particular form there are 14 pairs
I'm building a .Net MVC app, where I'm using one particular view to generate
I replace multiple image in imageview at particular time(2second).image are stay in drawable folder.and
I need to make an app available for just one particular device model (or
I've been working on a complex app with one main dashboard. I don't particularly

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.