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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:59:10+00:00 2026-06-15T17:59:10+00:00

I have a submenu with buttons set up in xml which works fine. <?xml

  • 0

I have a submenu with buttons set up in xml which works fine.

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Single menu item
     Set id, icon and Title for each menu item
-->
 <item android:id="@+id/menu_level"
      android:title="Set Level" >
      <menu>
          <group android:checkableBehavior="single">
            <item android:id="@+id/one"
                  android:checked="false"
                  android:title="One" />
            <item android:id="@+id/two"
                  android:title="Two" />
            <item android:id="@+id/three"
                  android:title="Three" />
         </group>
     </menu>
 </item>

<item android:id="@+id/menu_save"
      android:icon="@drawable/icon_save"
      android:title="Save" />

 <item android:id="@+id/menu_about"
      android:icon="@drawable/icon_bookmark"
      android:title="About">

     <menu>
         <item  android:id="@+id/copyright"
                android:title="(c) John Beukema 2012">
         </item>
     </menu>

   <item/>
</menu>

I access it as follows:

@Override
public boolean onOptionsItemSelected(MenuItem item)
{
    Editor editor = PreferenceManager
            .getDefaultSharedPreferences(this).edit();


    switch (item.getItemId())
    {

    case R.id.menu_save:
        return true;

    case R.id.menu_recall:
        return true;

    case R.id.menu_level: {
        return true;    
    }
    case R.id.menu_about:

        return true;

    case R.id.one:
        star = 1;
        editor.putInt("Star", 1);              
        editor.commit();
        item.setChecked(true);
        return true;

    case R.id.two:
        star = 2;
        editor.putInt("Star", 2);              
        editor.commit();
        item.setChecked(true);
        return true;

    case R.id.three:
        star = 3;
        editor.putInt("Star", 3);              
        editor.commit();
        item.setChecked(true);
        return true;

    case R.id.menu_delete:
        return true;

    case R.id.menu_preferences:
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
   } 
}

So far no problem. But I want to load the buttons on start up from preferences.

@SuppressWarnings("deprecation")
@SuppressLint("NewApi")
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    SharedPreferences preferences = PreferenceManager
          .getDefaultSharedPreferences(this);



    star = preferences.getInt("Star", 1);

    MenuItem one = (MenuItem) findViewById(R.id.one);
    MenuItem  two = (MenuItem ) findViewById(R.id.two);
    MenuItem  three = (MenuItem) findViewById(R.id.three);

    switch(star)  
    {
    case 1:
        one.setChecked(true); break;



    case 2:
        two.setChecked(true); break;

    case 3:
        three.setChecked(true); break
        } 
   }
}

This compiles but hangs. How do I address the submenu buttons?

  • 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-15T17:59:11+00:00Added an answer on June 15, 2026 at 5:59 pm

    I dont think you can do findviewbyid on menuitem. You need to set or unset the checked items in onprepareoptionsmenu

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

Sidebar

Related Questions

I have a SubMenu in a ContextMenu which ItemSource is set to a expression
I have to code animated menu buttons for my Android app. It will be
I have a set of menu's visable at http://carbonyzed.co.uk/menu/2/ Now when you click the
I have put together a navigation bar which expands a submenu on hover. See
I have a UINavigationController with 3 levels of hierarchy: Menu->Submenu->Details. Menu and Submenu are
I have a css horizontal menu with a menu / submenu display working on
I have an application that has a top level navigation menu which consists of
I have a navigation menu which when an item is selected on the menu,
I have a horizontal menu that contains buttons. Clicking on the button opens a
I have this html <ul id=menu> <li><input type=button id=btnMenu-1 class=btnMenu value=pitillo></li> <ul class=subMenu> <li><input

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.