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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:05:52+00:00 2026-06-02T10:05:52+00:00

I have created a Spinner and have populated it with values for my app

  • 0

I have created a Spinner and have populated it with values for my app which will work out alcohol units in drinks.

The spinner hold the different type of measures of drinks Pint, Half Pint, Bottle and Can.

The alcohol units are worked out by talking the volume of the drink which is held in the spinner times by amount of drinks times by alcohol percentage over 1000.

What I want to happen is when the user selects some of the values form the spinner such as pint it will add the volume of a pint into the equation.

This is the code I have for the spinner

int pint,half,bottle,can;
Spinner beerspinner;
Spinner spinner = (Spinner) findViewById(R.id.beerspinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.drinks_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

I want to somehow match the values from the spinner to an integer so I can carry out the equations.

pint = 568;
half = 284;
bottle = 275;
can = 440;

I haven’t really explained it very well here is my complete code so you can get a better idea of what I want to be done.

public class AppTestActivity extends Activity {
int pint,half,bottle,can;
Spinner beerspinner;
Button submit, reset;
EditText ABV,quantity;
TextView units, error;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ABV = (EditText) findViewById(R.id.ABV);
submit = (Button) findViewById(R.id.submit);
reset = (Button) findViewById(R.id.reset);
units = (TextView) findViewById(R.id.units);
error = (TextView) findViewById(R.id.error);
quantity= (EditText) findViewById(R.id.quantity);

Spinner spinner = (Spinner) findViewById(R.id.beerspinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.drinks_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);

submit.setOnClickListener(new clicker());
 }
class clicker implements Button.OnClickListener{

public void onClick(View v){

pint = 568;
half = 284;
bottle = 275;
can = 440;

String number,percentage;
Float calc; 

percentage = ABV.getText().toString();
number = quantity.getText().toString(); 
calc = Float.parseFloat(number)*Float.parseFloat(percentage)/1000;
units.setText(calc.toString());
}

Currently the code takes the number of drinks times it by the alcohol percentage and then divides by 1000 and I need it to add the drink types from the spinner to the equation.

  • 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-02T10:05:54+00:00Added an answer on June 2, 2026 at 10:05 am

    Crate an int in your activity.

    int drinkType; 
    

    Use setOnItemSelected listener for the spinner:

    spinner.setOnItemSelectedListener(new OnItemSelectedListener()
    {
          public void on ItemSlected(...)
              int selectedIndex=spinner.getSelectedItenPosition();
    
              if(selectedIndex==0) //pint for example
                    drinkType = 568;
              //do this for other drink types
    }
    

    And in your code above you can do

    calc = Float.parseFloat(number)*Float.parseFloat(percentage)/1000+ drinkType;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an application for ContactsContract... I have created a spinner which brings
I have an application, which has a Spinner that I want populated with some
I have created an application having tab activity which in turn has 5 different
I have created a spinner which is automatically updated with appliance names when a
I have created a bar chart which is a improvement of bar graph on
I have created an app in android and it requires some data to be
I have created a spinner with 3 options: Beginner, Advanced and Pro. When one
I am working on an Android Tablet app. I have created a custom action
Hi I have created a spinner using the following code. I didn't set any
I have created a drop down in my android application using a spinner. However

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.