Android 将第一个意向和的值转换为第二个意向和
我在编写体重指数计算器时遇到了麻烦 我想在第二个活动中仅显示已计算的值,但仅当我按下按钮,然后直接转到第二个活动时才计算该值,而不显示任何值 谢谢 主要活动 第二观众Android 将第一个意向和的值转换为第二个意向和,android,android-intent,Android,Android Intent,我在编写体重指数计算器时遇到了麻烦 我想在第二个活动中仅显示已计算的值,但仅当我按下按钮,然后直接转到第二个活动时才计算该值,而不显示任何值 谢谢 主要活动 第二观众 在按钮侦听器中,请在计算后调用开始活动 Button b = (Button) this.findViewById(R.id.button1); b.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View
在按钮侦听器中,请在计算后调用开始活动
Button b = (Button) this.findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str1 = e1.getText().toString();
String str2 = e2.getText().toString();
if (TextUtils.isEmpty(str1)) {
e1.setError("Insira o peso em Kg");
e1.requestFocus();
return;
}
if (TextUtils.isEmpty(str2)) {
e2.setError("Insira a altura em Cm");
e2.requestFocus();
return;
}
//Get the user values from the widget reference
float weight = Float.parseFloat(str1);
float height = Float.parseFloat(str2) / 100;
float bmiValue = calculateBMI(weight, height);
String bmiInterpretation = interpretBMI(bmiValue);
tv4.setText(String.valueOf(bmiValue));
Intent i = new Intent(MainActivity.this, Resultado.class);
i.putExtra("result1", tv4.getText().toString());
startActivity(i);
}
});
完成所有计算后开始您的活动
String bmiInterpretation = interpretBMI(bmiValue);
tv4.setText(String.valueOf(bmiValue));
Intent i = new Intent(MainActivity.this, Resultado.class);
i.putExtra("result1", tv4.getText().toString());
startActivity(i);
Button b = (Button) this.findViewById(R.id.button1);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String str1 = e1.getText().toString();
String str2 = e2.getText().toString();
if (TextUtils.isEmpty(str1)) {
e1.setError("Insira o peso em Kg");
e1.requestFocus();
return;
}
if (TextUtils.isEmpty(str2)) {
e2.setError("Insira a altura em Cm");
e2.requestFocus();
return;
}
//Get the user values from the widget reference
float weight = Float.parseFloat(str1);
float height = Float.parseFloat(str2) / 100;
float bmiValue = calculateBMI(weight, height);
String bmiInterpretation = interpretBMI(bmiValue);
tv4.setText(String.valueOf(bmiValue));
Intent i = new Intent(MainActivity.this, Resultado.class);
i.putExtra("result1", tv4.getText().toString());
startActivity(i);
}
});
String bmiInterpretation = interpretBMI(bmiValue);
tv4.setText(String.valueOf(bmiValue));
Intent i = new Intent(MainActivity.this, Resultado.class);
i.putExtra("result1", tv4.getText().toString());
startActivity(i);