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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:06:00+00:00 2026-06-09T02:06:00+00:00

I want to add a Dialog with 2 buttons edit and remove (only remove

  • 0

I want to add a Dialog with 2 buttons edit and remove(only remove implemented actually) when I use longClick (the standard click opens the item details)

so I have tried to follow the guide on this link

and I have added

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

@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
            .getMenuInfo();

    switch (item.getItemId()) {
    case R.id.remove_item:

        final String[] listItem = getItemId();

        String idItemSel = listItem[info.position];

        delItem(idItemSel);
        adapter.notifyDataSetChanged();
        return true;
    }
    return false;
}

(where adapter is my list adapter)

and I have configured the listener in this way

list.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                .....

            }
        });


        list.setOnItemLongClickListener(new OnItemLongClickListener() {

            public boolean onItemLongClick(AdapterView<?> parent, View view,
                    int position, long id) {
                view.showContextMenu();
                return true;

            }
        });

All works fine but when I use long click the app crash with this error (on invocation of view.showContextMenu();) :

08-02 18:13:12.079: E/AndroidRuntime(7780): FATAL EXCEPTION: main
08-02 18:13:12.079: E/AndroidRuntime(7780): java.lang.StackOverflowError
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:1995)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onItemLongClick(MyItems.java:615)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.widget.AbsListView.showContextMenuForChild(AbsListView.java:2001)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at android.view.View.showContextMenu(View.java:2520)
08-02 18:13:12.079: E/AndroidRuntime(7780):     at detailer.myapp.it.MyItems$6.onIt

Any solution to the problem or alternatives to view a simple context dialog when I long press a list item?

  • 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-09T02:06:02+00:00Added an answer on June 9, 2026 at 2:06 am

    You seem to have registered your ListView for a ContextMenu and set an OnItemLongClickListener that calls showContextMenu(), this creates a circular logic:

    • The OnItemLongClickListener calls the ContextMenu,
    • The ContextMenu calls the OnItemLongClickListener,
    • The OnItemLongClickListener calls the ContextMenu,
    • The ContextMenu calls the OnItemLongClickListener,
    • etc. until the stack overflow occurs

    To fix this:

    First, remove the OnItemLongClickListener since it is redundant with a ContextMenu.

    Second, double check how you are using your ContextMenu. You have the menu saved in the layout folder and you don’t need to invoke showContextMenu() if you have already used registerForContextMenu().


    To setup a ContextMenu, simply pass the whole ListView to registerForContextMenu():

    registerForContextMenu(list);
    

    You’ll need an XML like this:

    <menu xmlns:android="http://schemas.android.com/apk/res/android">
        <item
            android:id="@+id/edit"
            android:title="@string/edit" />
        <item
            android:id="@+id/remove"
            android:title="@string/remove" />
    </menu>
    

    Save this in a new folder res/menu, I named it context_menu.xml.

    Then change your method to create the ContextMenu:

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

    Now each row will automatically open a ContextMenu when long clicked.


    If you need help with editing and deleting row, post the code that you use to create the ListView and Adapter.

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

Sidebar

Related Questions

I want to add some custom HTML between the buttons on a jQuery dialog
I want add new Feed item on entity persist and update. I write this
i want to add Layout Dynamically on Add button click and on Dynamic Layout
I want to add those little buttons many webpages have that are simply a
I'm new to jQuery, and now I want to use jQuery-UI Dialog to show
I want to add the menu to my app, like when you click delete
I would like to add a generic dialog with Ok and Cancel buttons support
I want add UIGestureRecognizerDelegate to UIWebView,but failed. if [self.view addsubView:webView]; So UIWebView is ok,but
I want add label to every row in tableview at right side of the
I want add my custom sidebar next right column all page. Please check 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.