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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:55:58+00:00 2026-06-11T15:55:58+00:00

I have an options menu with a checkbox. I can check and uncheck the

  • 0

I have an options menu with a checkbox. I can check and uncheck the checkbox when it has been clicked by the user which is fine. However, I am using SharedPreferences to store the value of this checkbox, so what I also need to do is to initialise the checkbox with whatever is stored in the SharedPreferences pref value i.e. if the pref is true/false, set the checkbox to checked/unchecked.

I guess I need to put some code inside my onCreateOptionsMenu, and I obviously need to use .setChecked(preference) to set the checkbox, but how do I programatically reference the checkbox itself?

The menu is created using:

public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options_menu, menu);
return true;
}

The checkbox can be checked/unchecked using:

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.two_week:
            if (item.isChecked()) {
                item.setChecked(false);
            }
            else {
                item.setChecked(true);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
     }
}
  • 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-11T15:56:00+00:00Added an answer on June 11, 2026 at 3:56 pm

    I think the only method that you are missing is Menu’s findItem(). You can easily load any SharedPreferences (called prefs here) like this:

    SharedPreferences prefs;
    ...
    
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.options_menu, menu);
    
        boolean checked = prefs.getBoolean("two weeks", false);
        menu.findItem(R.id.two_week).setChecked(checked);
        return true;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose we have a menu which presents the user with some options: Welcome: 1)
My app has a few activities, all have an options menu, which is the
I have setup my site with 5 pages which are my menu options. When
I have created a horizontal menu with 5 tab options using a ul and
I have six menu options in my webapp, and when the user hovers over
I have this view which generates interface language options menu def lang_menu(request,language): lang_choices =
I have a custom adapter populating a listview. Each row has a checkbox which
Almost all games today have a video options menu where you can choose the
I have an options menu with an Add/Remove option that, when clicked, shows a
I have a Search Button in my Options menu, which shows a Dialog with

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.