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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:48:42+00:00 2026-05-24T23:48:42+00:00

I have created an inflater menu which brings up two buttons, one links to

  • 0

I have created an inflater menu which brings up two buttons, one links to a list of clickable items, which when clicked closes the menu and returns to the main screen view. However the other button brings up a list of radio buttons which work but the return key has to be pressed to close this menu. I want it to just close automatically once one of the options has been selected.

Any suggestions on how to make this happen would be much appreciated, thanks in advance for any help.

Here’s my code:

@Override
public boolean onCreateOptionsMenu(Menu menu) { //creates the menu options that appear when the menu button is pressed
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.mainmenu, menu);
    return true;
} 
public boolean onOptionsItemSelected(MenuItem item) { // assigns one button in the menu to display Rhythm and then further options

    final CharSequence[] Rhythms = {"Sinus Rhythm", "Atrial Fibulation", "Atrial Flutter", "Junctional Rhythm", "SVT", "Ventricular Tachycardia"};
    AlertDialog.Builder builder = new AlertDialog.Builder(this);

    builder.setTitle("Interpretation of ECG waveform");
    builder.setItems(Rhythms, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int Rhythm) {
            Toast.makeText(getApplicationContext(), Rhythms[Rhythm], Toast.LENGTH_SHORT).show(); // add a save function here to utilise the onclick function
        }                                                                                        // saved file should match the ecg file name and also be loaded when app is started
    });
    final CharSequence[] annotations = {"A", "B", "B-","C", "C-", "D", "F"}; // assigns a new button with the annotation options

    AlertDialog.Builder builder1 = new AlertDialog.Builder(this);
    builder1.setTitle("Evaluate ECG quality");
    builder1.setSingleChoiceItems(annotations, 0, new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int item) {
             Toast.makeText(getApplicationContext(), annotations[item], Toast.LENGTH_SHORT).show();  // again add a save function here, this should be able to override the 
                                                                                                     // annotation coding written by Daniel.
        }
    });

           setCancelable(true);    

    switch (item.getItemId()) { 

    case R.id.annotatebutton: // when annotation button is click display annotation options
        builder1.show();
        return true;

    case R.id.rhythmbutton: // when rhythm button is clicked display rhythm options
        builder.show();        
        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-05-24T23:48:43+00:00Added an answer on May 24, 2026 at 11:48 pm
    case R.id.annotatebutton:
        builder1.show();
        closeOptionsMenu();
        return true;
    case R.id.rhythmbutton:
        builder.show();        
        closeOptionsMenu();
        return true;
    default:
        return super.onOptionsItemSelected(item);
    

    You can close the options menu programmatically with closeOptionsMenu()

    see http://developer.android.com/reference/android/app/Activity.html#closeOptionsMenu()

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

Sidebar

Related Questions

I have ordinary activity with Option Menu, which I created by this code: @Override
I have created two imageViews promatically as shown below: public void createImageViews(Integer count){ ImageView[]
I have created two classes. I want to have a button on class 1
Dear friends, I have created one music app. It contains some collection of albums,
I have created a custom ContextMenu . But when I call the menu, the
I have the following function that is called after a menu item is clicked.
I have created a custom Base Adapter class, to populate a list view with
Ok so far I have created this, and my items are being displayed. Lets
I am creating an application in which I have to open a previously created
I have two layouts and I am inflating it one after another ,I want

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.