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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:01:18+00:00 2026-05-25T16:01:18+00:00

I got a sub-menu that I add with values, I then want to set

  • 0

I got a sub-menu that I add with values, I then want to set them up by reading the currentViewMode variable that contain the current view mode… The code below must check the first one but it doesn’t. Please advise.

private enum ViewMode
{
    NORMAL,
    SATELLITE,
    HYBRID
}
private ViewMode currentViewMode = ViewMode.NORMAL;

private final int  SUB_MENU_GROUP = 1;
private final int SUB_MENU_ITEM_NORMAL = 1;
private final int SUB_MENU_ITEM_SATELLITE = 2;
private final int SUB_MENU_ITEM_HYBRID = 3;

public boolean onCreateOptionsMenu(Menu menu) {
    SubMenu sub = menu.addSubMenu(0, 1, 0, R.string.menu_mapwindow_viewmode).setIcon(R.drawable.ic_menu_refresh);
    sub.add(SUB_MENU_GROUP, SUB_MENU_ITEM_NORMAL, Menu.NONE, this.getString(R.string.mapwindow_viewmode_normal));
    sub.add(SUB_MENU_GROUP, SUB_MENU_ITEM_SATELLITE, Menu.NONE, this.getString(R.string.mapwindow_viewmode_satellite));
    sub.add(SUB_MENU_GROUP, SUB_MENU_ITEM_HYBRID, Menu.NONE, this.getString(R.string.mapwindow_viewmode_hybrid));
    sub.setGroupCheckable(SUB_MENU_GROUP, true, true);

    if (this.currentViewMode == ViewMode.NORMAL)
        sub.findItem(SUB_MENU_ITEM_NORMAL).setChecked(true);
    else if (this.currentViewMode == ViewMode.SATELLITE)
        sub.findItem(SUB_MENU_ITEM_SATELLITE).setChecked(true);
    else if (this.currentViewMode == ViewMode.HYBRID)
        sub.findItem(SUB_MENU_ITEM_HYBRID).setChecked(true);

    return super.onCreateOptionsMenu(menu);
}

  @Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId())
    {
        case SUB_MENU_ITEM_NORMAL:
            item.setChecked(!item.isChecked());
            this.currentViewMode = ViewMode.NORMAL;
            Log.i(this.getClass().getName(),  "Normal");
            break;
        case SUB_MENU_ITEM_SATELLITE:
            item.setChecked(!item.isChecked());
            this.currentViewMode = ViewMode.SATELLITE;
            Log.i(this.getClass().getName(),  "Satellite");
            break;
        case SUB_MENU_ITEM_HYBRID:
            item.setChecked(!item.isChecked());
            this.currentViewMode = ViewMode.HYBRID;
            Log.i(this.getClass().getName(), "Hybrid");
            break;
        default:
            super.onOptionsItemSelected(item);
    }
    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-25T16:01:18+00:00Added an answer on May 25, 2026 at 4:01 pm

    You should make the checkbox updates in onPrepareOptionsMenu (instead of onCreateOptionsMenu), as it will be invoked on every menu open.
    Create only called before the very first.
    (its not sure if this is causing your problem, but is possible, so worth a try, and makes your code safer, anyway)

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

Sidebar

Related Questions

I've got a sub-select in a query that looks something like this: left outer
I've got an expandable css menu that is acting a bit weird in ie,
I've got a menu like: <ul class=sub> <li><a href=#>New</a></li> <li><a href=#>Open</a></li> <li><a href=#>Save</a></li> <li><a
My first project with Hibernate/JPA and Play!, I've got a menu that once working,
I've got an animated dropdown menu with animated subnavs that works beautifully in FF,
I've got a flyout menu on a site that I'm building. I'm using a
Say you've got a MethodInfo, or any other sub-class of MemberInfo for that matter,
I've got the following code: Public Delegate Sub SetStatusBarTextDelegate(ByVal StatusText As String) Private Sub
Got a class that serializes into xml with XMLEncoder nicely with all the variables
Got some code that is not mine and its producing this warning atm: iehtmlwin.cpp(264)

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.