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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:46:48+00:00 2026-06-02T05:46:48+00:00

I am working on an android application. My application should compute the number of

  • 0

I am working on an android application.
My application should compute the number of calories based on Age, Weight, Height and Gender using the method CalculateCalories() and store all the values in a database.

The application works fine for male, but for female it always gives me 0.0 !

Here is the piece of code.

 public class ProfileActivity extends Activity {

DatabaseAdapter usertable = new DatabaseAdapter(this);
User user = new User();
RadioButton rb_male;
RadioButton rb_female;
RadioButton rb_light;
RadioButton rb_moderate;
RadioButton rb_heavy;
EditText name;
EditText age,weight,height;

String gender;
String level;
float bmr, calnum;

String finalGender;

@Override
protected void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    setContentView(R.layout.createprofile);

    rb_male = (RadioButton) findViewById(R.id.maleradiobutton);
    // String male = rb_male.getText().toString();

    rb_female = (RadioButton) findViewById(R.id.femaleradiobutton);
    // String female = rb_female.getText().toString();

    rb_light = (RadioButton) findViewById(R.id.lightradiobutton);
    rb_moderate = (RadioButton) findViewById(R.id.moderateradiobutton);
    rb_heavy = (RadioButton) findViewById(R.id.heavyradiobutton);

    Button addUser = (Button) findViewById(R.id.checkcreateprofilebutton);

    Button gendercheck = (Button) findViewById(R.id.gendercheck);

    gendercheck.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (rb_male.isChecked()) {
                gender = "male";
            }
            if (rb_female.isChecked()) {
                gender = "female";
            }
            Toast.makeText(ProfileActivity.this, (CharSequence) gender,
                    Toast.LENGTH_LONG).show();

        }
    });

    Button checkactivity = (Button) findViewById(R.id.checkactivity);
    checkactivity.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (rb_light.isChecked()) {
                level = "light";
            }
            if (rb_moderate.isChecked()) {
                level = "moderate";
            }
            if (rb_heavy.isChecked()) {
                level = "heavy";
            }

            Toast.makeText(ProfileActivity.this, (CharSequence) level,
                    Toast.LENGTH_LONG).show();
        }
    });
    addUser.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {



             name = (EditText) findViewById(R.id.namefield);
             age = (EditText) findViewById(R.id.agefield);
            int Age=Integer.parseInt(age.getText().toString());


             weight = (EditText) findViewById(R.id.weightfield);
             int Weight=Integer.parseInt(weight.getText().toString());

             height = (EditText) findViewById(R.id.heightfield);
             int Height = Integer.parseInt(height.getText().toString());


            float calnumber =calculateCalories(Age,Weight,Height,level);

            Log.d("test", "adding");

             name = (EditText) findViewById(R.id.namefield);
             age = (EditText) findViewById(R.id.agefield);
             weight = (EditText) findViewById(R.id.weightfield);
             height = (EditText) findViewById(R.id.heightfield);

            usertable.open();
            long id = usertable.createUser(name.getText().toString(), age
                    .getText().toString(), gender, weight.getText()
                    .toString(), height.getText().toString(), level,calnumber);

            String newId = String.valueOf(id);

            Toast.makeText(ProfileActivity.this, "user added",
                    Toast.LENGTH_LONG).show();

            Toast.makeText(ProfileActivity.this, newId, Toast.LENGTH_LONG)
                    .show();

            // Cursor c = usertable.getUser(17);
            // if (c.moveToFirst())
            // {
            // Toast.makeText(ProfileActivity.this, "name:"+ c.getString(1)+
            // "age"+c.getString(2), Toast.LENGTH_LONG).show();
            // }

            usertable.close();

            Intent Filling = new Intent();
            Filling.setClass(ProfileActivity.this, FillingActivity.class);
            startActivity(Filling);

        }
    });

}




public float calculateCalories(int age, int weight, int height, String level) {


    if (rb_male.isChecked()) {

         bmr = 66.5f + (13.75f * weight) + (5.003f * height)
                - (6.755f * age);

        if (rb_light.isChecked()) {
            calnum = bmr * 1.375f;
        }
        if (rb_moderate.isChecked()) {
            calnum = bmr * 1.55f;
        }
        if (rb_heavy.isChecked()) {
            calnum = bmr * 1.725f;
        }
        if (rb_female.isChecked()) {

            bmr = 665 + (9.563f * weight) + (1.850f * height)
                    - (4.676f * age);

            if (rb_light.isChecked()) {
                calnum = bmr * 1.375f;
            }
            if (rb_moderate.isChecked()) {
                calnum = bmr * 1.55f;
            }
            if (rb_heavy.isChecked()) {
                calnum = bmr * 1.725f;
            }

        }
    }
    return calnum;

}}
  • 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-02T05:46:51+00:00Added an answer on June 2, 2026 at 5:46 am

    And what exactly is surprising?

    This piece of code:

       if (rb_female.isChecked()) {
    
            bmr = 665 + (9.563f * weight) + (1.850f * height)
                    - (4.676f * age);
    
            if (rb_light.isChecked()) {
                calnum = bmr * 1.375f;
            }
            if (rb_moderate.isChecked()) {
                calnum = bmr * 1.55f;
            }
            if (rb_heavy.isChecked()) {
                calnum = bmr * 1.725f;
            }
    
        }
    

    Is placed inside this check:

    if (rb_male.isChecked()) {
    

    So it will never be executed. Restructure your if/else.

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

Sidebar

Related Questions

I am working in android chat application. I used SmartFox server. I am using
I am working on application which should go into android 2.2(Froyo) and android 2.3(GingerBread)
I am working on android chat application. I am facing a problem in send
I am working in an android application and I want to implement a Gallery.
I am working on an android application which can be used to capture the
I am working on an android Application where I am willing to get input
I'm working on a client-server Android application and trying to figure out how to
I am working on a Mapview in my android application, in which i have
I am working on a fairly basic screen layout for my first Android application
I have integrated Zxing library in my Android application, and it is Perfectly working,

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.