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

  • Home
  • SEARCH
  • 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 6698361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:34:08+00:00 2026-05-26T06:34:08+00:00

i have this problem which i never expect it to occur. When i pressed

  • 0

i have this problem which i never expect it to occur. When i pressed on the Menu button, the program display the Menu and after i click on one of the items from the Menu, it pops out a item list for me to choose. However, just when the item list pops out, some of the code in onOptionsItemSelected() was called when i did not even select any item. After i selected on of the items, onOptionsItemSelected() got called again (i know this is called because an item was selected). Can anyone tell me how to solve this problem or even why is this happening? Below is the coding…

Btw, the ‘count’ is just an integer variable to show whether onOptionsItemSelected() was called as it would increment each time when called.

public boolean onCreateOptionsMenu(Menu menu) {

    SubMenu sendMenu = menu.addSubMenu("Change Profile");

    int size = profileNames.size();

    for(int i=0; i<size; i++){
        sendMenu.add(0,i,0,profileNames.get(i).toString());
    }

    menu.add(1, size, 0, "Configuration");
    return super.onCreateOptionsMenu(menu);
}




@Override
public boolean onOptionsItemSelected(MenuItem item) {

    count++;

    Toast toast1 = Toast.makeText(this, "Count: "+count, Toast.LENGTH_SHORT);
    toast1.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast1.show();

    selectedProfileName = null;
    //change the map according to the selected profile name
    if(item.getItemId()<=profileNames.size()-1){
        selectedProfileName = profileNames.get(item.getItemId());
        setContentView(new SampleView(this));
    }
    else{
        Intent myIntent=new Intent(this,configurationTabWidget.class);
        startActivity(myIntent);
    }
    //just to re-draw the map with the new selected profile name        
    return true;
}
  • 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-26T06:34:08+00:00Added an answer on May 26, 2026 at 6:34 am

    You are selecting two items – first you select the “Change Profile” menu item, and then you select the particular item from the SubMenu.

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

Sidebar

Related Questions

Consider this problem: I have a program which should fetch (let's say) 100 records
So I have this problem, which has never happened to me before. I am
I have this little problem, that I cannot figure out which arguments to pass
I'm quite new to hibernate and have stumbled on this problem, which I can't
I have this .bat script which I use to maven package my application. Problem
Problem Hello all! I have this code which takes my jpg image loops through
I'm training code problems like UvA and I have this one in which I
This problem is bizarre. I have never encountered anything like it before. I am
I have a program which references a DLL. Code in this DLL gets the
I have a jar on the classpath which contains a hibernate.properties. This causes problems

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.