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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:49:11+00:00 2026-05-14T21:49:11+00:00

The context menu is not popping up on the long click on the list

  • 0

The context menu is not popping up on the long click on the list items in the list view. I’ve extended the base adapter and used a view holder to implement the custom list with textviews and an imagebutton.

adapter = new MyClickableListAdapter(this, R.layout.timeline, mObjectList);
       list.setAdapter(adapter);
       registerForContextMenu(list);  

Implementation of onCreateContextMenu

  @Override
 public void onCreateContextMenu(ContextMenu menu, View v,
   ContextMenuInfo menuInfo) {
  // TODO Auto-generated method stub
  super.onCreateContextMenu(menu, v, menuInfo);

  Log.d(TAG, "Entering Context Menu");

   menu.setHeaderTitle("Context Menu");

  menu.add(Menu.NONE, DELETE_ID, Menu.NONE, "Delete")
  .setIcon(R.drawable.icon);
 }

The XML for listview is here

 <ListView
    android:id="@+id/list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />

I’ve been trying this for many days. I think its impossible to register Context-menu for a custom list view like this. Correct me if I am wrong (possibly with sample code).

Now I am thinking of a adding a button to the list item and it displays a menu on clicking it. Is it possible with some other way than using Dialogs?

Any help would be much appreciated..

  • 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-14T21:49:12+00:00Added an answer on May 14, 2026 at 9:49 pm

    Why didn’t you use ListActivity?

    In my ListActivity I have:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        /* setContentView() and all stuff that happens in this method */
        registerForContextMenu(getListView());
    }
    
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        AdapterView.AdapterContextMenuInfo info;
        try {
            info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        } catch (ClassCastException e) {
            Log.e(TAG, "bad menuInfo", e);
        return;
        }
    
        Something something = (Subway) getListAdapter().getItem(info.position);
        menu.setHeaderTitle(something.getName());
        menu.setHeaderIcon(something.getIcon());
        menu.add(0, CONTEXT_MENU_SHARE, 0, "Do something!");
    }
    
    @Override
    public boolean onMenuItemSelected(int featureId, MenuItem item) {
        AdapterView.AdapterContextMenuInfo info;
        try {
            info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        } catch (ClassCastException e) {
            Log.e(TAG, "bad menuInfo", e);
            return false;
        }
    
        switch (item.getItemId()) {
            case DO_SOMETHING:
                /* Do sothing with the id */
                Something something = getListAdapter().getItem(info.position);
                return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Testdriven.net not available in the right-click context menu??
I need to remove some items from right-click context menu, but the toolbar does
I have a list view which has been registered for a context menu. For
The Click Event form a Context Menu Item is not raised when the cursor
WebBrowser context menu or custom context menu does not shown over combobox. How to
I'm adding a custom context menu item to documents (and not folders) in a
how to show a context menu when you right click within a QGLWidget?
I have a ListActivity and I want to implement context menu for each of
I've got a popup context menu on a list box, and there are two
I'd like a context menu on the caption bar right click any tips/samples pref

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.