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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:01:14+00:00 2026-05-27T15:01:14+00:00

So I’m interested in creating a custom context menu for each of my list

  • 0

So I’m interested in creating a custom context menu for each of my list items when they are long clicked. I saw this implemented in the Baconreader app, and thought it would be as simple as:

  1. Create one LinearLayout (or whatsoever) when populating the listview
  2. When an item is long-clicked, hide the item (View.GONE) and add the LinearLayout to the list item’s parent.
  3. When needed, show the list item and remove the LinearLayout from it’s parent.

I successfully managed to hide the list items onItemLongClick, but it turns out that you can’t add Views to a ListView (d’oh). But that’s got to be the way Baconreader does it. I can’t figure it out. Here’s some code I tried:

listView.setOnItemLongClickListener(new OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> arg0,
        View arg1, int arg2, long arg3) {
             arg1.setVisibility(View.GONE); // hide the list item, works

             // trying to add a TextView after a list
             // item's position, doesn't work.
             listView.addView(textView, arg2);

             return true;
    }
});

Here’s a sample what it should look like:A screenshot from my lovely Nexus S

So the List Item is hidden and a custom context menu (seems like a ViewGroup) is placed directly over the list item’s position. But how?

Edit: Solved. The updated code:

list_item.xml

    <TextView
        android:id="@+id/list_item_title"
        .....
     />

</FrameLayout>

The java code

listView.setOnItemLongClickListener(new OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> arg0,
        View arg1, int arg2, long arg3) {
             ((FrameLayout)arg1).addView(w);
             return true;
    }
});

And of course you have to use SimpleAdapter instead of ArrayAdapter.

  • 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-27T15:01:15+00:00Added an answer on May 27, 2026 at 3:01 pm

    Just a quick tip: what if you don’t hide the list item and add the context menu to the list, but instead add the context menu to the list item?

    For example, wrap the current layout of the list item into a FrameLayout. Then when long-clicked, just add the context menu to this FrameLayout instead? (and if needed hide the first child of the FrameLayout). This wouldd also guarantee that the context menu will have the same size as the list item.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this

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.