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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:50:53+00:00 2026-06-05T12:50:53+00:00

I have a ListView. I implemented OnItemClickListener to open a ContextMenu when an item

  • 0

I have a ListView. I implemented OnItemClickListener to open a ContextMenu when an item is clicked.

lv = getListView();
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            showMenu(view);
        }
    });

And the code to create menu.

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

public void showMenu(View v) {
    registerForContextMenu(v);
    openContextMenu(v);
}

My problem is, when I clicked on one item of ListView, it does open the Menu. But if I go back to the ListView, I can’t click that item again. The same for other items, it can’t be click after close the menu. Can anyone help me with this?

  • 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-05T12:50:54+00:00Added an answer on June 5, 2026 at 12:50 pm

    You’ve set that up incorrectly. You register for context menu when you set the adapter, not in a button click.

    It should look like this:

    setListAdapter(lists);
    registerForContextMenu(getListView());
    

    Then you have your onCreateContextMenu and onContextItemSelected methods (I create mine programatically, but your inflated one woudl work just as well):

    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.setHeaderTitle("List Operations");
        menu.add(0, v.getId(), 0, "Edit List");
        menu.add(0, v.getId(), 0, "Delete List");
    }
    
    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
                .getMenuInfo();
        if (item.getTitle() == "Edit List") {
          //  Do your edit stuff here
        } else if (item.getTitle() == "Delete List") {
          // Do your delete stuff here
        }
        return super.onContextItemSelected(item);
    }
    

    You don’t need to use onItemClick unless you want to do something on a short press of the item (context menu is long press).

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

Sidebar

Related Questions

I have implemented an application on ListView in my application i have used getListView()
I have a listview where each item correlates to an instance of an item
I am trying to update the ListView with timer . I have implemented the
I have implemented an adapter for my ListView which extends BaseAdapter. My list items
i have a listview and implemented onclick and also onfling.problem is when i do
I have following code: public class ShowActivity extends ListActivity implements OnItemClickListener { /** Called
I have a listView. In that listView i have implemented onTouchListener. Every things work
I have implemented a ListView in my Android application. I bind to this ListView
I have implemented a list view. Each item in my list view has two
I want to have one ListView that when I click on the item the

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.