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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T14:49:18+00:00 2026-06-02T14:49:18+00:00

in the code below the user enters a set of attributes and then they

  • 0

in the code below the user enters a set of attributes and then they need to be stored and then calculated using the CaluculateCalories() it returns the number of calories (Calnum)that I want to store in the sharedpreferences too. How is it possible to do that?
Here is the piece of code, i just need some lines to be added in the Savepreferences, i just dont know how.

protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.createprofile);
    SharedPreferences customSharedPreference = getSharedPreferences(
            "myCustomSharedPrefs", Activity.MODE_PRIVATE);

    name = (EditText) findViewById(R.id.namefield);
    name.setText(customSharedPreference.getString("namepref", ""));

    age = (EditText) findViewById(R.id.agefield);
    // int Age = Integer.parseInt(age.getText().toString());
    age.setText(customSharedPreference.getString("agepref", ""));

    genderradiogroup = (RadioGroup) findViewById(R.id.radioGroup2);
    rb_male = (RadioButton) findViewById(R.id.maleradiobutton);
    rb_female = (RadioButton) findViewById(R.id.femaleradiobutton);
    genderradiogroup.check(customSharedPreference.getInt("genderprefs",
            rb_male.getId()));

    weight = (EditText) findViewById(R.id.weightfield);
    // int Weight = Integer.parseInt(weight.getText().toString());
    weight.setText(customSharedPreference.getString("weightpref", ""));

    height = (EditText) findViewById(R.id.heightfield);
    // int Height = Integer.parseInt(height.getText().toString());
    height.setText(customSharedPreference.getString("heightpref", ""));

    levelofactivity = (RadioGroup) findViewById(R.id.radioGroup3);
    rb_light = (RadioButton) findViewById(R.id.lightradiobutton);
    rb_moderate = (RadioButton) findViewById(R.id.moderateradiobutton);
    rb_heavy = (RadioButton) findViewById(R.id.heavyradiobutton);
    levelofactivity.check(customSharedPreference.getInt("levelpref",
            rb_light.getId()));

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

    addUser.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            savePreferences();

        }
    });

}

private void savePreferences() {

    SharedPreferences customSharedPreference = getSharedPreferences(
            "myCustomSharedPrefs", Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = customSharedPreference.edit();
    editor.putString("namepref", name.getText().toString());
    editor.putString("agepref", age.getText().toString());
    editor.putInt("genderprefs", genderradiogroup.getCheckedRadioButtonId());
    editor.putString("heightpref", height.getText().toString());
    editor.putString("weightpref", weight.getText().toString());
    editor.putInt("levelpref", levelofactivity.getCheckedRadioButtonId());

    editor.commit();
    finish();

}


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;
        }

    } else 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-02T14:49:23+00:00Added an answer on June 2, 2026 at 2:49 pm

    You set it like any other SharedPreference. What are you having trouble with? What have you tried?

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

Sidebar

Related Questions

the below code is working fine if the user enters the USN number that
my code like below public class User { public int ID { get; set;
Hi I'm using this code below to let a user draw their signature on
The code below allows the user to enter in a phrase in plain English,
I am working with NHibernate and I get this code below: public class User
I created a DatePicker user control (ASP code below, no code behind) which is
i use the code below to open a new window when a user drops
I have the code below on form so that the user submits the form
With the following code below, There is an error saying File /home/user/web_pro/info/views.py, line 184,
I am passing user defined classes over sockets. The SendObject code is below. It

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.