Determine your Ideal Weight by calculating your Body Mass Index on Android

Written by ssaurel | Published 2017/08/17
Tech Story Tags: weight-loss | android-app-development | android | android-apps | fitness

TLDRvia the TL;DR App

The Body Mass Index or Quetelet index is a value derived from the mass (weight) and height of an individual. The BMI is defined as the Body Mass divided by the square of the body height, and is universally expressed in units of kg/m².

The BMI lets to categorize a person as underweight, normal weight, overweight or obese based on the value. It lets you to know your Ideal Weight.

By calculating your Body Mass Index, you can find your ideal weight and find some help in your fight to lose weight for example. An easy way to calculate your BMI is to use a dedicated application available for Android smartphones and tablets. Named BMI Calculator Ideal Weight, this application is available in both versions on the Google Play Store :

BMI Calculator will let you to get your BMI just by entering your weight (in kg) and your height (in cm). You could access to the History of your calculated BMIs to follow the evolution of your BMI through the time.

Finally, you can share your BMI with your friends to motivate you if you are in a diet group. A tutorial learning you how to use BMI Calculator Ideal Weight is also available on YouTube :

Don’t hesitate to try the application and give your feedback in comments concerning the application.

Bonus

You are interested by the BMI Calculator and you are going to use it. It’s good but may be, you want more. Indeed, you could want to learn how to create yourself a BMI Calculator application for Android. As a bonus, I’m going to learn you how to make that yourself.

Get Android Studio

First thing to do is to get the Android Studio software, which is the official IDE offered by Google to create Android applications. You can get Android Studio just there : https://developer.android.com/studio/index.html

Once you have installed Android Studio, you just have to create a new Android Application Project.

Create the App’s Layout

First step for the application is to define a layout letting users to enter weight and height values to calculate the BMI index. Besides, we will need a button to launch the BMI calculation and also a TextView to display the result.

The layout will have the following form :

<a href="https://medium.com/media/aacaacfe067e29a9cc8687baeeffb7a8/href">https://medium.com/media/aacaacfe067e29a9cc8687baeeffb7a8/href</a>

Write the Java Code

Now, we can write the Java code in our Main Activity :

<a href="https://medium.com/media/6d18dbe71fef130aa17cfcd6ecaa9ddc/href">https://medium.com/media/6d18dbe71fef130aa17cfcd6ecaa9ddc/href</a>

When a user click on the calculate BMI button, the calculateBMI method is called. We get the values entered by the user for the weight and the height. The height is entered in centimeter. For the formula, we need to have a height in meter. So, we divide the value entered by 100. Then, we apply the formula to calculate the BMI :

float bmi = weightValue / (heightValue * heightValue);

With the BMI value, we can display the result on the user interface. We define the displayBMI method for that. To determine the diagnostic associated to the BMI value, we are going to use the table presented previously in this tutorial.

The last step is just to display the BMI value and the diagnostic in the result TextView. After that, you can try the application and enjoy the BMI Calculator in action :

To discover more tutorials on Android Development, don’t hesitate to visit the SSaurel’s Blog : https://www.ssaurel.com/blog


Written by ssaurel | Bitcoiner. Freedom Maximalist. Author of "The Truth About Bitcoin". Editor, In Bitcoin We Trust Newsletter.
Published by HackerNoon on 2017/08/17