问题描述
packagecom.demo.android.bmi;importjava.text.DecimalFormat;importandroid.app.Activity;importandroid.app.AlertDialog;importandroid.content.Context;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;importandroid.widget.EditText;importandroid.widget.TextView;publicclassBmiActivity<Bmi>extendsActivity{@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_bmi);Buttonbutton=(Button)findViewById(R.id.submit);button.setOnClickListener(calcBMI);}privateOnClickListenercalcBMI=newOnClickListener(){publicvoidonClick(Viewv){DecimalFormatnf=newDecimalFormat("0.00");EditTextfieldheight=(EditText)findViewById(R.id.height);EditTextfieldweight=(EditText)findViewById(R.id.weight);doubleheight=Double.parseDouble(fieldheight.getText().toString())/100;doubleweight=Double.parseDouble(fieldweight.getText().toString());doubleBMI=weight/(height*height);TextViewresult=(TextView)findViewById(R.id.result);result.setText("yourbmiis"+nf.format(BMI));TextViewfieldsuggest=(TextView)findViewById(R.id.suggest);if(BMI>25){fieldsuggest.setText(R.string.advice_heavy);}elseif(BMI<20){fieldsuggest.setText(R.string.advice_light);}else{fieldsuggest.setText(R.string.advice_average);}openOptionsDialog();}privatevoidopenOptionsDialog(){newAlertDialog.Builder(Bmi.this).setTitle("关于AndroidBMI").setMessage("AndroidBMICalc").show();}};}
解决方案
解决方案二:
我也遇到同样的问题,求解?
解决方案三:
关键是看你Bmi这个类是不是context啊