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

The Archive Base Latest Questions

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

I am developing a simple Restaurant application in Android, I used menus and inflated

  • 0

I am developing a simple Restaurant application in Android, I used menus and inflated submenu items corresponding to each menu item, I wanted to know a way of how to add the name of the dish to list only if the user selects yes in the alert dialog and viceversa.
Here is my code

   public boolean onOptionsItemSelected(MenuItem m)
    {
        super.onOptionsItemSelected(m);
        switch(m.getItemId())
        {
            case R.id.Chicken_Biryani:
            selectedItem.add(m.getTitle().toString());
            cost.add(150);
            Toast.makeText(getApplicationContext(),"Hyderabadi special: Chicken   biryani costs 150 Rs"+selectedItem, Toast.LENGTH_LONG).show();
            showDialog(ALERT_DIALOG); 
            break;

            case R.id.Butter_Chicken:
            selectedItem.add(m.getTitle().toString());
            cost.add(150);
            Toast.makeText(getApplicationContext(),"Now with Punjabi Tadka: Butter Chicken costs 150 Rs", Toast.LENGTH_LONG).show();
            showDialog(ALERT_DIALOG);   

            break;

                   ........

      public Dialog onCreateDialog(int id) {
        switch(id)
        {
        case ALERT_DIALOG:
        AlertDialog.Builder ab = new AlertDialog.Builder(this);
        ab.setTitle("Buy Items");
        ab.setMessage(" You have added the item to your cart ");
        ab.setIcon(R.drawable.shopcart);
        ab.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){         
            Toast.makeText(getApplicationContext(),"Item added to cart your cart contains "+selectedItem.size()+" Items", Toast.LENGTH_LONG).show();    
            }});    
    Dialog ad = ab.create();
        return ad;  
        }
        return null;    

        }

// how do i pass the data of the onOptionsItemSelected to the list only if the user selects yes in the alertdiaolog

  • 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-25T06:18:42+00:00Added an answer on May 25, 2026 at 6:18 am

    Please see this question for more information. It links to another answer which talks about how and when you can use notifyDataSetChanged.

    I think in your AlertDialog you would want an “Add” button and a “Cancel” button to cancel adding it to the cart. Upon clicking add, your would insert the item into the users cart. To add another button to your AlertDialog you would use ab.setNegativeButton(…) just as you did with the setPositiveButton. This is just my take on it, am I correctly understanding your use of onCreateDialog – or is it used only to tell the user it has been added?

    Please see this question for more specific help on how to implement within an AlertDialog.

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

Sidebar

Related Questions

I am developing simple travel agent android application. When application starts it loads list
im developing a simple Mxml application using flex 3. I have used simple text
I am developing a simple application for Android in which I am using a
i am developing one simple application for android mobile here i am using two
I'm developing a simple application for Android devices. I need to create a directory,
Hi I am developing a simple application based upon ASP.NET MVC. I have altered
I am developing a simple web page to be viewed after an iphone application
I'm developing simple pages navigation portlet, and for each page I would like to
i'm developing simple cms application. i want to integrate number of hits for some
I have 6 months experience with Android, developing simple UI-based applications. Now 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.