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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:12:29+00:00 2026-06-01T06:12:29+00:00

On an app that I’m working on, I need a context menu to show

  • 0

On an app that I’m working on, I need a context menu to show up if a user performs a longClick on a tab, which would allow them to close the tab. I can’t seem to find a way to add a listener to a tab though. I either need each tab to have its own listener or the listener needs to be able to tell which tab had the longClick performed on it, as it won’t always be the active tab.

Any ideas?

  • 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-01T06:12:31+00:00Added an answer on June 1, 2026 at 6:12 am

    I appreciate that an answer has been accepted but if you want to utilise the built-in ContextMenu capabilities rather than set onLongClickListeners on the TabWidget itself, you can do this as follows…

    Example, my current TabActivity adds tabs in a for loop and to register each for context menu I do the following.

    for (int tabNumber = 1; tabNumber < 8; tabNumber++) {
        ...
        spec = tabHost.newTabSpec(tag).setIndicator(indicator).setContent(intent);
        tabHost.addTab(spec);
    
        View v = tabWidget.getChildAt(tabNumber - 1);
        registerForContextMenu(v);
        ...
    }
    

    Then in my Activity I simply override onCreateContextMenu(...) and onContextItemSelected (MenuItem item)

    @Override
    public void onCreateContextMenu (ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        ...
        // The parameter v is the actual tab view and not the TabWidget
        // this makes it easy to get the indicator text or its tag in order
        // to easily identify which tab was long-clicked and build the menu
        ...
    }
    
    @Override
    public boolean onContextItemSelected (MenuItem item) {
        ...
        // Process selected item here
        ...
    }
    

    There’s no need to set an OnLongClickListener on any views explicitly as that is done by the call to registerForContextMenu(...). Also, the ContextMenu creation and selection handling is all handled for you by the ContextMenu methods exposed by Activity.

    Unless you need to handle all of this stuff yourself (for a custom context menu layout for example) it seems easier to just use what’s buit-in to Activity.

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

Sidebar

Related Questions

The app that I'm working on allows the user to pick an image from
I have a WPF App that implements a ListView. I would like to show
The App that I'm working on requires to parse a very big Json file
I have a PHP app that creates a CSV file which is forced to
The app that I'm currently working on is supposed to overlay a square image.
Say that the user has started my App and then switched off to use
I have an app that will display Lotto Max numbers, I need to make
I have inherited an app that generates a large array for every user that
I have an android app that appears to be working fine - but I
The app that i am working on uses UIWebViews to display vimeo videos. Instead

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.