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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:43:21+00:00 2026-06-13T21:43:21+00:00

I have a MainActivity that holds reference to a FragmentAdapter and a ViewPage. In

  • 0

I have a MainActivity that holds reference to a FragmentAdapter and a ViewPage.
In this activity, I add two fragments to a List and then this list to the FragmentAdapter:

fragments.add(Fragment.instantiate(this, Fragment1.class.getName()));       
fragments.add(Fragment.instantiate(this, Fragment2.class.getName()));

Now, I am successfully able to slide through those two Fragments. In fact, both of them are ListFragments. In each fragment I list many items.

For each item, I can click-hold and a Menu item will appear.

The problem occuring is that on Fragment1, the public boolean onContextItemSelected(MenuItem item) is sucessfull invoked inside Fragment1 (added the breakpoint inside this fragment).

When doing the same test in Fragment2, the breakpoint from Frag1 is invoked and not from Frag2. And, obviously, data from Frag1 is shown in Frag2.

Anyone has ever seen this?

I instanciate the menu in both fragments like this:

@Override
    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, v, menuInfo);
        menu.add(Menu.NONE, R.id.share, Menu.NONE, getString(R.string.share));
        menu.add(Menu.NONE, R.id.delete, Menu.NONE, getString(R.string.delete_all));
    }

Regards,
Felipe

  • 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-13T21:43:22+00:00Added an answer on June 13, 2026 at 9:43 pm

    Basically whichever fragment is instantiated first will get priority. See this link for a solution using invalidateOptionsMenu. Basically the options menu will persist until you tell android that it is invalid. On older systems you could change the menu in onPrepareOptionsMenu but because the actionbar has icons from the optionsmenu you need to destroy it completely.

    So when you page to a new fragment, simply invalidate the options menu. For older devices, check in onPrepareOptionsMenu to see what fragment is visible and make those options present.

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

Sidebar

Related Questions

I have a main activity, that holds the main menu. This menu has an
I have an activity ( MainActivity.java ) in which content view is like this
I have this situation where i have to start an activity from my mainActivity.
Let's say we have a standard MainActivity that extends Activity . It contains onCreate
Good day. I have an app that has one main activity which holds 3
I am making an app in which i have a main activity that the
Splash I have main activity UI startup operations that take between 5-10 seconds (that
I have an activity, I'll call it mainactivity for now. And I want to
I have a design of activities like this I have one main activity and
Can someone help me find the problem? I have MainActivity, that when I go

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.