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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:32:26+00:00 2026-06-10T08:32:26+00:00

In my Spinner I have a String Array for it {sedentary, lightly active, moderately

  • 0

In my Spinner I have a String Array for it {sedentary, lightly active, moderately active and heavily active} (this is the calculation of one’s BMR)

What I want to do is get the selected item in a Spinner.

For example, when I click on sedentary, for sedentary has a value of 1.2, the result of the bmr is multiplied by 1.2. But I can’t seem to get it work for me.

Please do check my code below:

private void calculateMen(){    
    String f1 = etft.getText().toString();
    String f2 = etin.getText().toString();
    String f3 = etweight.getText().toString();
    String f4 = etage.getText().toString();

    if ( (f1.isEmpty() || f2.isEmpty() || f3.isEmpty() || f4.isEmpty() ) ) 
    {   // call for custom toast
        viewErrorToast();
    } 
    else
    {
        // Metric Formula for BMR (Men) English Unit
        // 66 + ( 6.2377 x weight in kilos ) + 
        //( 12.7084 x height in cm ) - ( 6.7550 x age in years )
        String age, in, ft, weight;
        Double answer;
        age =  etage.getText().toString();
        in =  etin.getText().toString();    
        ft = etft.getText().toString();
        weight = etweight.getText().toString();

        if (spinnerText.equals("Sedentary"))
        {     
            answer =  ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.2 ); 
            //*  Double.parseDouble(actAnswer) ;    
            BigDecimal bd = BigDecimal.valueOf(answer);
            bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);         
            etanswer.setText(bd.toString()); 
        }
        else if (spinnerText.equals("Lightly Active"))
        {
            answer =  ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.375 ); 
            //*  Double.parseDouble(actAnswer) ;    
            BigDecimal bd = BigDecimal.valueOf(answer);
            bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
            etanswer.setText(bd.toString()); 
        }
        else if (spinnerText.equals("Moderately Active"))
        {
          answer =  ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.55 ); 
          //*  Double.parseDouble(actAnswer) ;    
          BigDecimal bd = BigDecimal.valueOf(answer);
          bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
          etanswer.setText(bd.toString()); 
        }
        else if (spinnerText.equals("Heavily Active"))
        {
          answer =  ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) ) - ( 6.8 * Double.parseDouble( age ) ) ) * 1.725 ); 
          //*  Double.parseDouble(actAnswer) ;    
          BigDecimal bd = BigDecimal.valueOf(answer);
          bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
          etanswer.setText(bd.toString()); 
        }
        // call for custom toast
        viewBMRSavedToast();
    }

} // end of calculateMen method
  • 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-10T08:32:27+00:00Added an answer on June 10, 2026 at 8:32 am

    Please try modifying the code as below :

    Create a field :

    private HashMap<String, Double> spinnerValues;
    

    From onCreate of your activity, call the below function :

    private void createSpinnerValues(){
        spinnerValues=new HashMap<String, Double>();
        spinnerValues.put("Sedentary", 1.2);
        spinnerValues.put("Lightly Active", 1.375);
        spinnerValues.put("Moderately Active", 1.55);
        spinnerValues.put("Heavily Active", 1.725);
    }
    

    Then find your modified function to calculate as below :

    private void calculateMen(){
    
        //Your Code Goes here...
    
         String age, in, ft, weight;
         Double answer;
         age =  etage.getText().toString();
         in =  etin.getText().toString();    
         ft = etft.getText().toString();
         weight = etweight.getText().toString();
    
         answer=getAnswer(age,in,ft,weight,getSelectedItemValueFromSpinnerText(spinnerText));
    
         BigDecimal bd = BigDecimal.valueOf(answer);
         bd = bd.setScale(2, BigDecimal.ROUND_FLOOR);
    
         etanswer.setText(bd.toString()); 
    
         // call for custom toast
         viewBMRSavedToast();
        }
    
    private Double getAnswer(String age, String in, String ft, String weight,
            Double selectedItemValueFromSpinner) {
        double answer = ( ( 66 + ( 6.2377 * Double.parseDouble( weight ) ) + 
                 ( 12.7084 * ( Double.parseDouble( in ) * 12 + Double.parseDouble( ft ) ) )
                 - ( 6.8 * Double.parseDouble( age ) ) ) * selectedItemValueFromSpinner ); 
        return answer;
    }
    
    private Double getSelectedItemValueFromSpinnerText(String spinnerText) {
        return spinnerValues.get(spinnerText);
    }
    

    Don’t forget to include your existing code at : //Your Code Goes here…

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

Sidebar

Related Questions

I have a spinner set up like this: ArrayAdapter<String> states = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,
I have spinner with array list thats work fine, but i want to sort
I have a Spinner.onItemSelected() method and I want to be able to have an
I have one spinner, and I am populating that. I have list of values
I have a Spinner and a SimpleCursorAdapter . For odd/even rows on this spinner
I'm creating a spinner in my layout xml files and setting an string array
i have an array which is populated in the spinner adapter. now i wanna
I have two spinners (day_spin and time_spin) in one Activity . I want to
I have a JSON/string/array, not sure what it is now as it’s been through
I have the following code populating a spinner, JSONObject jsonResponse = new JSONObject(new String(buffer));

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.