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 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

I work on a app which has only one way to get a working
I'm developing a Mac App in Java that logs into any one of our
I need to make an app available for just one particular device model (or
I want to make a really simple iphone app: one screen with a single
When I have one app.config in my main project I always have to duplicate
I'm looking into writing a simple synchronization ability into my app and one of
I have one console app that is doing some lengthy syncing to an ftp
One of the core fields present on several of my app's major database tables
We have an app that uses simple one way binding with a GridView to
How would one change the view on the screen programmatically in an iPhone app?

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.