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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:34:13+00:00 2026-06-14T06:34:13+00:00

menu item is not displaying dialog box below is my code when user click

  • 0

menu item is not displaying dialog box below is my code when user click on menu item it should take him to login page where to add that code.

public boolean onOptionsItemSelected(MenuItem item, int id) {
    switch (item.getItemId()) {
        case R.id.Login:
             startActivity(new Intent(this, Login.class));
             return true;
        case R.id.About:
         startActivity(new Intent(this, About.class));
            return true;
        case R.id.Post_Ads:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setMessage("Are you sure you want to exit?")
                   .setCancelable(false);
            AlertDialog alert = builder.create();
                    alert.show();
                    startActivity(new Intent(this, Login.class));
             return true;


          }
    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-14T06:34:15+00:00Added an answer on June 14, 2026 at 6:34 am

    Try this , it should work:

    public boolean onOptionsItemSelected(MenuItem item) {
                // TODO Auto-generated method stub
                switch (item.getItemId()) {
                case R.id.Login:
                    Toast.makeText(getApplicationContext(), "Fired 1", Toast.LENGTH_SHORT).show();
                     startActivity(new Intent(this, Login.class));
                     return true;
    
                case R.id.About:
        Toast.makeText(getApplicationContext(), "Fired 2", Toast.LENGTH_SHORT).show();
                 startActivity(new Intent(this, About.class));
    
                    return true;
                            case R.id.Post_Ads:
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setMessage("Are you sure you want to exit?")
                           .setCancelable(false);
                    AlertDialog alert = builder.create();
                            alert.show();
                            startActivity(new Intent(this, Login.class));
    
                     return true;
    
    
                  }
            return super.onOptionsItemSelected(item);
    
            }
    

    There is no method called public boolean onOptionsItemSelected(MenuItem item, int id) in the Activity class to handle option menu's.

    The method to handle such events is onOptionsItemSelected(MenuItem).

    For your menu items to getting displayed, you have to use following method too,
    Check whether you have implemented this method also or not,

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

    And a small correction,

    You have implemented the following Alertdialog method,

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("Are you sure you want to exit?")
                       .setCancelable(false);
                AlertDialog alert = builder.create();
                        alert.show();
                        startActivity(new Intent(this, Login.class));
    

    You haven’t provided any ok or cancel button here,
    And also you made it setCancellable(false). So User cannot choose any options here.

    So i am suggesting you to give Ok and Cancel Button here and do what you want to do inside the onClick() method. Like the following example:

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("Are you sure you want to exit?")
                       .setCancelable(false);
                AlertDialog alert = builder.create();
                alert.setButton("Ok", new DialogInterface.OnClickListener() {
    
                    public void onClick(DialogInterface dialog, int which) {
                        // Do call some activity or close the app. Do what you wish to;
    
                    }
                });
    
    alert.setButton2("Cancel", new DialogInterface.OnClickListener() {
    
                    public void onClick(DialogInterface dialog, int which) {
                        // Do stay in the current activity or something else. Do what you wish to;
    
                    }
                });
                        alert.show();
    
                 return true;
    

    Hope, It might be helpful.

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

Sidebar

Related Questions

The Click Event form a Context Menu Item is not raised when the cursor
If I do not create an Edit->Copy menu item and assign it the shortcut
I'm adding a custom context menu item to documents (and not folders) in a
jQuery 1.4: $('#menu li:last:not(.ignore)').addClass('last'); HTML: <div id=menu> <ul> <li>item 1</li> <li>item 2</li> <li class=ignore>item3</li>
Im trying to create a menu item so when a user clicks on the
How do you insert a custom QAction as a menu item, not in the
I've a menu item linking to a page that requires authentication to be visited.
Here I tried to make option menu, but menu is not displaying on screen,
I have multilingual website in joomla and want to hide one menu item (not
I am trying to use a context menu I created for a Dialog Box,

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.