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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T21:12:09+00:00 2026-06-03T21:12:09+00:00

I have a TabHost with 2 Fragments, both lists. The onCreateContextMenu works fine for

  • 0

I have a TabHost with 2 Fragments, both lists. The onCreateContextMenu works fine for both, but both onContextItemSelected are “pointing” to the first Fragment class. I’m using different names for the lists in the XML files, so the ID isn’t the same.

Here is the code for both onCreateContextMenu

@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        int itemID = info.position;

        Map m = (HashMap) this.listView.getAdapter().getItem(itemID);

        menu.setHeaderTitle(getString(R.string.options));
        menu.add(0, v.getId(), 0, activity.getString(R.string.delete));
    }

And here onContextItemSelected for the first Fragment, second one is pretty much the same code just changing var names. In fact this doesn’t change anything to the question, since this method only runs on the first Fragment, even when I’m on the second list.

@Override
    public boolean onContextItemSelected(MenuItem item) {
        ContextMenuInfo menuInfo = (ContextMenuInfo) item.getMenuInfo();
        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        int itemID = info.position;
        Map m = (HashMap) this.listView.getAdapter().getItem(itemID);
        processId = Integer.parseInt(m.get("processId").toString());

        activity.setSupportProgressBarIndeterminateVisibility(true);
        runBackground(activity.getString(R.string.accessingECM), false, false, ACTION_REMOVE);
        return true;
    }

This is how I register for context menu on the onActivityCreated method. Note that the onCreateContextMenu works for both Fragment.

listView = (ListView) this.view.findViewById(R.id.listProcess);
        registerForContextMenu(listView);

I tried to change the menu.add() 1st and 3rd parameters to (1,1) and (1,2). Also tried both to be Menu.NONE. Still doesn’t work.

Thanks

  • 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-03T21:12:11+00:00Added an answer on June 3, 2026 at 9:12 pm

    For a tabhost (in my experience) you need to set up a single onCreateContextMenu in the activity for the tabhost and use a switch to get the appropriate menus/actions.

    Example:

    // ***************************************************************
    // Create the various context menus depending on which list it is from
    // ***************************************************************
    @Override
    public void onCreateContextMenu(ContextMenu menu, View v,
            ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        switch (v.getId()) {
        case R.id.list1: {
            menu.setHeaderTitle("Tool CC Menu");
            menu.add(0, v.getId(), 0, "Edit/Add Cutter Comp Info");
            menu.add(0, v.getId(), 0, "Clear Cutter Comp Info");
            break;
        }
        case R.id.list2: {
            menu.setHeaderTitle("WPC Menu");
            menu.add(0, v.getId(), 0, "Edit WPC Info");
            menu.add(0, v.getId(), 0, "Clear WPC Info");
            break;
        }
        }
    }
    // ***************************************************************
    // Create the various context menu actions based on which list
    // ***************************************************************
    @Override
    public boolean onContextItemSelected(MenuItem item) {
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
                .getMenuInfo();
        cc_id_int = (int) info.id;
        if (item.getTitle() == "Edit/Add Cutter Comp Info") {
            showDialog(CCEDIT_DIALOG_ID);
        } else if (item.getTitle() == "Clear Cutter Comp Info") {
            showDialog(CLEARCC_DIALOG_ID);
        } else if (item.getTitle() == "Edit WPC Info") {
            removeDialog(WPCEDIT_DIALOG_ID);
            showDialog(WPCEDIT_DIALOG_ID);
        } else if (item.getTitle() == "Clear WPC Info") {
            showDialog(CLEARWPC_DIALOG_ID);
        }
        return super.onContextItemSelected(item);
    }
    

    Hope this helps!

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

Sidebar

Related Questions

I have a tabHost based app, with fragments, It works fine if I use
Using this sample : I have make my own Fragment that holds tabhost and
Guys, I have tried different samples using the list-view with fragments,In my application i
I'm having thoughts abut my current app. I have this TabHost class with two
I'd like to show a different fragment in a TabHost, for every tab. But
Hey, I have a TabHost with two tabs, each with an Activity. The first
I am trying to have a tabhost that it contained in a fragment, where
I have an application using TabActivity but it is being rendered incorrectly on ICS.
I have created four tabs using tabhost, and placed four listviews in each like
I have a tabhost where I need to use onTabChanged listener, but it does

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.