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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:18:29+00:00 2026-05-31T03:18:29+00:00

I’m trying to make a simple order system. So the user selects a burger

  • 0

I’m trying to make a simple order system. So the user selects a burger type from a spinner, then the user can enter in the quantity and then there is some math taking place in the background which sets a text view at the bottom with the total price. I’m not sure what method I’m meant to use so that it is updated dynamically when the user changes the text view quantity.

If i just say that all burgers are 2.50, i need some sort of method saying, if/when data is entered into the edit text , take that data and then times it by 2.50 and set it in the total text view below. I’m just unsure on the method part of it so it’s dynamic and will change when the edit text quantity is altered.

[code]

package placeorder.com;

import java.util.Random;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.AdapterView.OnItemSelectedListener;

public class Food extends Activity {

    String[] burgersarray, chipsarray, saladarray;
    Random order = new Random();
    double bquantity, hamburger, burgertotal;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.food);

        EditText burgerquantity = (EditText) findViewById(R.id.et_burger);          
        TextView total = (TextView) findViewById(R.id.tv_total);
        Spinner burgers = (Spinner) findViewById(R.id.sp_burgers);      

        burgersarray = getResources().getStringArray(R.array.burgers);
        chipsarray = getResources().getStringArray(R.array.chips);
        saladarray = getResources().getStringArray(R.array.salad);      
        TextView orderid = (TextView) findViewById(R.id.tv_orderid);        

        int randomorder = order.nextInt(9999);
        orderid.setText("Order ID: " + randomorder);        


        ArrayAdapter<String> burgersadapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_dropdown_item, burgersarray);

        burgers.setAdapter(burgersadapter);


        burgers.setOnItemSelectedListener(new OnItemSelectedListener()

        {

            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {

                String burger = (String) arg0.getSelectedItem();    
            }

            public void onNothingSelected(AdapterView<?> arg0) {
            }
        });     





    }



}

[/code]

  • 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-31T03:18:30+00:00Added an answer on May 31, 2026 at 3:18 am

    You’ll have to implement a TextWatcher for your EditText. First make an array that will hold the prices of the burgers(mapping the burgers types from the spinner) and an int field that will hold the current selection from the spinner:

    double[] prices = {1d, 2d, 3d};
    int currentSelection = 0;
    

    then implement the TextWatcher for your EditText:

    burgerquantity.addTextChangedListener(new TextWatcher() {
    
                public void onTextChanged(CharSequence s, int start, int before,
                        int count) {
                    // TODO Auto-generated method stub
    
                }
    
                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                    // TODO Auto-generated method stub
    
                }
    
                public void afterTextChanged(Editable s) {
                    double result = Integer.parseInt(s.toString())
                            * prices[currentSelection]; //obtain the total
                    total.setText("" + result); //set the result
                }
    

    Also in your spinner listener set the currentSelection field:

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {
                        currentSelection = arg2;
    //this is needed because the user could enter a value in the EditText but change to another burger category and so you update the total for the new price
                        if (!burgerquantity.getText().toString().equals("")) {
                            double result = Integer.parseInt(burgerquantity.getText()
                                    .toString()) * prices[currentSelection];
                            total.setText("" + result);
                        }
                    }
                });
    

    NOTE: You’ll have to take care about the exception that could arise when parsing the value from the EditText(for example if the user enters a value and then deletes all the numbers you’ll have an exception because the app will try to parse an empty string)

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:

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.