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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:42:40+00:00 2026-06-18T10:42:40+00:00

I saw an app where if you press the button it would play a

  • 0

I saw an app where if you press the button it would play a ring tone, then if you kept it down, a message boxed came up asking you if you wish to save the sound file. I would like to have my app detect if a button was pressed down for like a couple seconds.

I cannot figure out how to detect if a button was held down for a long time. I tried Googling it, but came up empty.

  • 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-18T10:42:42+00:00Added an answer on June 18, 2026 at 10:42 am

    Apparently you have not read about onLongClickListener huh?

    Read the following links:

    http://developer.android.com/reference/android/view/View.OnLongClickListener.html

    example code:

    buttonPlay.setOnClickListener(new OnClickListener() {
    
            @Override
            public void onClick(View v) {
                //Do something when clicked normally.
            }
        });
    
        buttonPlay.setOnLongClickListener(new OnLongClickListener() {
    
            @Override
            public boolean onLongClick(View v) {
                //Offer additional options when the view is held. 
                return true;
            }
        });
    

    Also, you may call registerForContextMenu() instead and pass the View you want to set the listener to. Reference

    Sample code:

    registerForContextMenu(textView);//Registering the TextView textview for longclicks
    

    You must write the code to inflate the context menu:

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.your_context_menu, menu);
        }       
    }   
    

    Where the id your_context_menu must be an .xml file created under the Res/Menu/ folder on your project.

    Once the menu is inflated, you must also write the code to respond to options being selected.

    @Override
    public boolean onContextItemSelected(MenuItem item) {
        Intent broadcast = new Intent();
        switch (item.getItemId()) {
        case R.id.menu_option_one:          
        //do something
        return true;
        default:
            return super.onContextItemSelected(item);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On an iOS App I saw such a Button: The same I would like
How can I write a private message in Facebook via iPhone app? I saw
I saw this in a HTML template for a web app: <img alt=mybutton src=/img/button.png?123456789
I published my first app in Google Play today, woot! Once I saw my
I saw a new app called Agile Reply which allows you to send a
I saw the Bug Me iPhone app and was intrigued by the ability to
I saw python codes to join two images in google app engine with 'composite'.
On uploading my App onto the market today, I saw that it is only
I saw some websites that (for example): if you want to view your message
In my app I saw some words with yellow squiggly underline. What they are

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.