BMI值得算法是“体重除以身高的平方”。html
程序的主体:java
package com.example;
import java.text.DecimalFormat;
import android.view.View;
import android.view.View.OnClickListener;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class EXAMPLEActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button=(Button)findViewById(R.id.submit);
button.setOnClickListener(calBMI);
}
private OnClickListener calBMI=new OnClickListener(){
public void onClick(View v){
DecimalFormat nf