Created
April 10, 2015 23:33
-
-
Save MostafaAnter/0d2242fe78d758e45931 to your computer and use it in GitHub Desktop.
Demonstration How you can implement Body Mass Index programically on android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mostafaAnter.bmi; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.view.Menu; | |
import android.view.View; | |
import android.view.View.OnClickListener; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.Toast; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final EditText x1=(EditText)findViewById(R.id.editText1); | |
final EditText x2=(EditText)findViewById(R.id.editText2); | |
Button b=(Button)findViewById(R.id.button1); | |
Button b1=(Button)findViewById(R.id.button2); | |
b.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
double d1=Double.parseDouble(x1.getText().toString()); | |
double d2=Double.parseDouble(x2.getText().toString()); | |
double d3=d2/100; | |
double d4=d1/(d3*d3); | |
String s =""; | |
if (d4<20) | |
s="You are Thin"; | |
if (d4==20) | |
s="You are fitness"; | |
if (d4>20&&d4<25) | |
s="You are fitness"; | |
if (d4>25&&d4<30) | |
s="You are overweight"; | |
if (d4>30&&d4<40) | |
s="You are obesity"; | |
if (d4>40) | |
s=" obese"; | |
Toast.makeText(MainActivity.this, "BMI is : " + d4 + "\n" + s, Toast.LENGTH_LONG).show(); | |
} | |
}); | |
b1.setOnClickListener(new OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
startActivity(new Intent(MainActivity.this, Second.class)); | |
} | |
}); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.main, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment