BMI calculator pro version
MAIN ACTIVITY .JAVA FILE
package com.example.viraj.ttest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText weight;
private EditText height;
private Button button;
private TextView result_bmi;
private TextView result_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
weight = (EditText) findViewById(R.id.id_weight);
height = (EditText) findViewById(R.id.id_height);
result_bmi = (TextView) findViewById(R.id.id_bmiis);
result_text = (TextView) findViewById(R.id.id_youare);
button = (Button) findViewById(R.id.id_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double weightget;
double heightget;
double bmi;
String msg;
if (weight.getText().toString().equals("") && height.getText().toString().equals(""))
{
Toast.makeText(getApplicationContext(),"NO VALID VALUES",Toast.LENGTH_LONG).show();
}
weightget = Double.parseDouble(weight.getText().toString());
heightget = Double.parseDouble(height.getText().toString());
bmi = heightget * heightget;
double bmi2= weightget / bmi;
result_bmi.setText(String.valueOf(bmi2));
if (bmi2<18.5)
{
result_text.setText("UNDER WEIGHT");
}
else if (bmi2 > 18.5 && bmi2 < 25)
{
result_text.setText("NORMAL");
}
else if (bmi2 > 25 )
{
result_text.setText("OVER WEIGHT");
}
}
});
}
}
ACTIVITY MAIN XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CDDC39"
tools:context="com.example.viraj.ttest.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:text="WEIGHT"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<EditText
android:id="@+id/id_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:text="HEIGHT"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_weight"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<EditText
android:id="@+id/id_height"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/id_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:background="#212121"
android:elevation="11dp"
android:text="CALCULATE BMI"
android:textAlignment="center"
android:textColor="#CDDC39"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_height"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/id_bmiis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="21dp"
android:text="YOUR B M I IS"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_button"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/id_youare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="40dp"
android:text="YOUR ARE"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_bmiis" />
</android.support.constraint.ConstraintLayout>
MAIN ACTIVITY .JAVA FILE
package com.example.viraj.ttest;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText weight;
private EditText height;
private Button button;
private TextView result_bmi;
private TextView result_text;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
weight = (EditText) findViewById(R.id.id_weight);
height = (EditText) findViewById(R.id.id_height);
result_bmi = (TextView) findViewById(R.id.id_bmiis);
result_text = (TextView) findViewById(R.id.id_youare);
button = (Button) findViewById(R.id.id_button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
double weightget;
double heightget;
double bmi;
String msg;
if (weight.getText().toString().equals("") && height.getText().toString().equals(""))
{
Toast.makeText(getApplicationContext(),"NO VALID VALUES",Toast.LENGTH_LONG).show();
}
weightget = Double.parseDouble(weight.getText().toString());
heightget = Double.parseDouble(height.getText().toString());
bmi = heightget * heightget;
double bmi2= weightget / bmi;
result_bmi.setText(String.valueOf(bmi2));
if (bmi2<18.5)
{
result_text.setText("UNDER WEIGHT");
}
else if (bmi2 > 18.5 && bmi2 < 25)
{
result_text.setText("NORMAL");
}
else if (bmi2 > 25 )
{
result_text.setText("OVER WEIGHT");
}
}
});
}
}
ACTIVITY MAIN XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CDDC39"
tools:context="com.example.viraj.ttest.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:text="WEIGHT"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<EditText
android:id="@+id/id_weight"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:text="HEIGHT"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_weight"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<EditText
android:id="@+id/id_height"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintHorizontal_bias="0.503"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<Button
android:id="@+id/id_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="40dp"
android:background="#212121"
android:elevation="11dp"
android:text="CALCULATE BMI"
android:textAlignment="center"
android:textColor="#CDDC39"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.502"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_height"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/id_bmiis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="21dp"
android:text="YOUR B M I IS"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_button"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp" />
<TextView
android:id="@+id/id_youare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="40dp"
android:text="YOUR ARE"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/id_bmiis" />
</android.support.constraint.ConstraintLayout>
0 comments:
Post a Comment