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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:14:03+00:00 2026-06-04T03:14:03+00:00

hi im getting a problem on my checkbox when check is change and if

  • 0

hi im getting a problem on my checkbox when check is change and if the checkbox is checked im displaying a alert dialog which take a input value and set the value to the text view and also im adding that value to the List here is my code

    @Override
    public void onCheckedChanged(CompoundButton checkBox, boolean isChecked)
    {
        TextView tvItem=(TextView)selectedView.findViewById(R.id.foodName); 
        final TextView tvQuantity=(TextView)selectedView.findViewById(R.id.quantity);

        orderList=new ArrayList<Order>();
        Order order=new Order();
        if(isChecked)
        {   

            final AlertDialog.Builder quantityAlert= new AlertDialog.Builder(TakeOrder.this);
            quantityAlert.setTitle("Quantity");
            quantityAlert.setMessage("Please enter quantity");

            final EditText input = new EditText(TakeOrder.this);
            input.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            quantityAlert.setView(input);

            quantityAlert.setPositiveButton("Ok", new DialogInterface.OnClickListener()
            {   
                public void onClick(DialogInterface dialog, int whichButton)
                {
                  value = input.getText();

                  tvQuantity.setText(value);

                }               
            });

            quantityAlert.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
            {
                  public void onClick(DialogInterface dialog, int whichButton)
                  {

                  }
                });

            quantityAlert.show();

            order.setItem(tvItem.getText().toString());
            order.setQuantity(Integer.valueOf(tvQuantity.getText().toString()));

            orderList.add(selectedPosition, order);
            Log.v("Item:",orderList.get(selectedPosition).getItem());
            Log.v("Quantity:",String.valueOf(orderList.get(selectedPosition).getQuantity()));
        }
        else
        {
            tvQuantity.setText("0");
            orderList.remove(selectedPosition);

        }




    }

The problem is that im showing the alert dialog first then taking the value of quantity from user but before i enter the value in alert box the Log.v executes and shows 0 that means in my List quantity is being added to 0…
but i want that the quantity value coming from alert dialog should be added to the List….
Can any one please help me…

  • 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-04T03:14:03+00:00Added an answer on June 4, 2026 at 3:14 am

    This makes sense becuase the code doesn’t stop and wait for your Alert Dialog to finish. It builds it, displays it, then moves on, which is where you are creating the value and adding it to the list.

    If you want it to only add when you press “Ok”, you need to put the Order modification and insertion code inside your “Ok” (positive button) handler.

    public void onClick(DialogInterface dialog, int whichButton)
    {               
        Order order=new Order();         
        value = input.getText();                      
        tvQuantity.setText(value);                       
    
        order.setItem(tvItem.getText().toString());             
        order.setQuantity(Integer.valueOf(value);
    
        orderList.add(selectedPosition, order);    
    
        Log.v("Item:",orderList.get(selectedPosition).getItem());             
        Log.v("Quantity:",String.valueOf(orderList.get(selectedPosition).getQuantity()));         
    } 
    

    I also put the Order intialization statement inside the onClick method because it isn’t used anywhere else. Save yourself one line of code if they select “Cancel” 🙂

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

Sidebar

Related Questions

We upgrated Nhibernate to 3.2 and getting problem in following scenarios: Public properties which
I am getting problem to read pdf files using iText in java. I can
i am getting problem as i have some data in a database tabel file
I am getting problem while setting up Session cookie using jersey. is there any
I have a problem getting password_Reset_confirm bit working. url: (r'^password_reset/$', 'django.contrib.auth.views.password_reset'), (r'^password_reset_done/$', 'django.contrib.auth.views.password_reset_done'), (r'^password_reset_confirm/(?P<uidb36>[0-9A-Za-z]+)-(?P<token>.+)/$',
I have a problem getting the right Price for a product based on Effectivity
I have a problem getting boost::multi_index_container work with random-access and with orderd_unique at the
I am having problem getting my tooltip to work when using the jQuery load()
I have a problem getting a private method using reflection. Even with BindingFlags.NonPublic and
I have this problem getting my newly created php project on Netbeans work on

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.