This single activity program, when run on Eclipse AVD, is accepting values, but not printing the value when button is clicked. I want to ask the error, if any and the reason why the program is not giving the desired results.
package com.msi.manning.calc_ur_bmi;
import android.os.;
import android.app.Activity;
import android.view.;
import android.widget.;
import android.net.;
import android.content.*;
import java.text.NumberFormat;
import android.util.Log;
public class Calc_ur_BMI extends Activity
{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bmi);
final EditText weightfield=(EditText) findViewById(R.id.weight);
final EditText heightfield=(EditText) findViewById(R.id.height);
final TextView bmifield=(TextView) findViewById(R.id.bmi);
final Button button=(Button) findViewById(R.id.calc);
button.setOnClickListener(new Button.OnClickListener() {
public void onClick(View view) {
try{
int num1=Integer.parseInt(weightfield.getText().toString());
float num2=Float.parseFloat(heightfield.getText().toString());
float ans=num1/num2*num2;
String S = null;
if(ans<19.5)
{
S = "Oh ho!!! You are undernourished...";
}
if(ans>=19.5&&ans<=25)
{
S = "You are appropriately nourished...";
}
if(ans>25)
{
S = "Oh ho!!! You are overweight...";
}
String str = Float.toString(ans);
bmifield.setText(str+S);
} catch (Exception e)
{
}
}
});
}
}