
[ad_1]
stay fit with smartphone

Anyone involved in the fitness community, or who aspires to stay fit, eventually comes across the idea of body fat percentage. In order to achieve a healthy and aesthetic physique, men must achieve a particularly high level of muscle mass, as well as a low body fat percentage for peak tone. Because of this, many in the fitness space, especially in the bodybuilding field, champion tracking their body fat percentage over other metrics such as BMI, which only considers height and overall weight.
However, tracking one’s progress can be difficult because medical equipment such as DEXA scans and baud pod scans can be expensive. Visually tracking progress can be difficult and inaccurate because it can take a long time to see progress.
Fortunately, the US Army Navy came up with the Body Fat Percentage Formula, which takes several measurements, such as your height and neck circumference, to determine your body fat percentage. Below we will demonstrate a simple body fat percentage calculator that I created using Android Studio to help determine one’s body fat calculations.

The Navy SEAL body fat calculator takes into account a range of variables. First, your biological gender (male or female) and then a series of three to four measurements depending on your above gender. For men, neck circumference and waist circumference, along with height, are of interest.
Women also need to get their hip circumference. To account for this, I have made four EditText
Fields (for body measurements) in Android Studio to allow gender selection with two switches, as seen below. A button executes the calculations, which include EditText
result field.

Since users can only be male or female for the purposes of this application, the first functionality I added was assist to toggle the above switch. As soon as a user checks that their gender is, let’s say, female, the male switch should be flipped.
If the female switch is off, the male switch should be on. Similarly, for the male switch. It’s fairly simple functionality, and it can be done in a . can be done by adding onClick
Functionality to switch and toggle the state of another based on input.
Here is the code for female sex switch with android id isFemale
(Creative, isn’t it?)
As seen above, the function call isChecked
returns a boolean variable of True
If the switch is on. For visual reference, in the app screenshot above, the female switch is on. The same was done for the male switch with ID isMale
,
Next, we will proceed to calculate the body fat percentage by clicking on the Calculate button. Before proceeding, we should get the value of all EditText
fields and make sure they are not empty. Zero values do not indicate good in mathematical formulas. If the required field is empty, a toast will be displayed to add data to the corresponding field. This is done as follows:
Once it is confirmed that all the values have been entered, we need to convert the values to integers and calculate. This count (seen on line 12) will be stored in a variable and placed in EditTextField
Result on line 14.
Once this code is implemented and tested in Android Studio, we can apply the same calculation for male subjects. Note that for me, nHip
The variable on line 12 is not included in the calculation. Once this is done, we have a fully functional mobile body fat percentage calculator for use by anyone who is interested.
At the time of writing this article, the above app is under review by Google. If all goes well, it will be published on the Play Store in the coming days. You’ll be able to link to it in my publisher profile linked below. As you can tell, I enjoy these afternoon projects a lot and find them a fun and engaging learning experience. Hopefully, this inspires one of your apps as well.
For the full code, please visit my GitHub. Happy hacking!
[ad_2]
Source link
#Creating #Body #Fat #Percentage #Calculator #Android #Studio #Alexa #Zetzalo #August