Sunday 18 June 2017

How to Create BMI Calculator Android App

How-to-Create-BMI-Calculator-Android-App


Download the Source Code for this BMI calculator

Downlod APK

I make this post simple as possible in the coding point of view.

You can read what is BMI and what is the formula to calculate our Body Mass Index.

I am simply explaining how to develop a BMI Calculator Android App.

Just read my previous posts like How to work with Buttons, How to add two numbers in Android and a Simple Calculator app.

If you have practiced the above examples it will be easy for you to do this BMI calculator app.

Create a new Project, drag and drop 2 Edittext to enter the height and weight, a button to calculate and a TextView to display the result also use the Hint.

BMI-calc-ui-design


After register the button, Edittext and Textview in MainActivity.java

register-ui-elements


After that write the below code inside the onClick()

@Override
    public void onClick(View arg0)
    {
       
       
        final DecimalFormat df2 = new DecimalFormat(".##");
        Double weight,height,heightinmeter,bmi,finalht;
        weight=Double.parseDouble(wt.getText().toString());
        height=Double.parseDouble(ht.getText().toString());
        heightinmeter=height*0.3048;
        finalht=heightinmeter*heightinmeter;
        bmi=weight/finalht;
        bmival.setText(""+df2.format(bmi));
       
        if(bmi<18.5)
         {
             res.setText("underweight");
         }
         else if(bmi>18.5&&bmi<24.9)
         {
             res.setText("normal weight");
         }
         else if(bmi>25&&bmi<29.9)
         {
             res.setText("overweight");
         }
         else if(bmi>30&&bmi<39.9)
         {
             res.setText("obesity");
         }
         else if(bmi>40)
         {
             res.setText("severe obesity");
         }
       
       
    }


BMI-calculator-source-code


  final DecimalFormat df2 = new DecimalFormat(".##");

this line is used to print only two digits after the dot for ex: 21.23 

heightinmeter=height*0.3048;
this line will convert your height in feet to height in meter

  Formula for calculating:

        heightinmeter=height*0.3048;// meter=feet*0.3048
        finalht=heightinmeter*heightinmeter;// height=meter*meter
        bmi=weight/finalht;
// bmi=weight/height

 This is the BMI standard

  if(bmi<18.5)
         {
             res.setText("underweight");
         }
         else if(bmi>18.5&&bmi<24.9)
         {
             res.setText("normal weight");
         }
         else if(bmi>25&&bmi<29.9)
         {
             res.setText("overweight");
         }
         else if(bmi>30&&bmi<39.9)
         {
             res.setText("obesity");
         }
         else if(bmi>40)
         {
             res.setText("severe obesity");
         }

The output will be

BMI-Calculator-Android-App

BMI-Calculator-Android-App

BMI-Calculator-Android-App
  
You can also add some colors to your app like this

BMI-Calculator-Android-App

BMI-Calculator-Android-App

I have used directly meter in this above example. 



16 comments :

  1. Nice very help full article ... Love it

    Visit This URL: Gold Bar Exporter

    ReplyDelete
  2. I’m happy I located this blog! From time to time, students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. nice one TubeMate PC Download Latest Version Plus Installation Guide

    ReplyDelete
  3. This is something that you just read and read. You just can’t get tired of it.
    mortgage calculator

    ReplyDelete
  4. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks app store

    ReplyDelete
  5. Numerous individuals know about Google's authentic Android advertise. While the market is incredible, interestingly, few out of every odd app is accessible there. crack for Apple device

    ReplyDelete
  6. The writer has outdone himself this time. It is not at all enough; the website is also utmost perfect. I will never forget to visit your site again and again. baixe o apk Lulubox download 2020

    ReplyDelete
  7. The reason could be either programming breakdown or equipment glitch, however a phone that isn't working is of no utilization to you.Handy reparatur Kiel

    ReplyDelete
  8. Thanks for providing information for the people who are looking for creative knowledge. even i have exploreed few website with the same but more information stories
    skillson9

    ReplyDelete
  9. When learning to play poker, a useful tool to have at your disposal is a poker odds calculator.  Such poker calculators allow you to calculate the odds that a given hand will be the best hand by the river.  Many poker decisions are based on your win odds and the use of such a tool allows you to hone you sense of the odds while away from the game until you get to a point where you become quite proficient at recognising the strength of a hand. hours calculator add

    ReplyDelete
  10. Shopping is either unadulterated happiness or torment contingent upon who you inquire. Despite which end of the range you are on, Android applications will assist you with setting aside cash and permit you to turn into a more productive customer (which I'm certain interests to a large portion of you).7 Downloads

    ReplyDelete
  11. For this reason it is advisable that you need to related study just before creating. You'll be able to publish far better submit in this way. SLA uptime calculator

    ReplyDelete
  12. Really I enjoy your site with effective and useful information. It is included very nice post with a lot of our resources.thanks for share. i enjoy this post. link para download do HappyMod apk

    ReplyDelete
  13. There are two types of scientific calculator, the most recent type being algebraic scientific calculators.matrix calculator Algebraic scientific calculators allow users to type in calculations in the order in which they have been written down.

    ReplyDelete
  14. Interestingly, those calculators have been utilized in places of work for pretty a long term for smooth and everyday calculations. But, confined of their functionalities, they have been sidelined and therefore got here different kinds of devices into the picture.Primary calculator

    ReplyDelete
  15. I was reading your article and wondered if you had considered creating an ebook on this subject. Your writing would sell it fast. You have a lot of writing talent. ajp150

    ReplyDelete