您好,我只是 android 的新手 ..我只是想问一下,我是否可以将 BMI 的计算从菜单窗口显示到另一个名为 android 中的 Register Window 的活动 ..因为当我运行此代码时,不会在注册窗口中显示结果。 。 谢谢你
*注册窗口 *
public void onClick(View v)
{
Intent intent = new Intent(Register.this, Menu.class);
intent.putExtra("response","counter");
startActivity(intent);
int weight = 0, height = 0, age = 0, answer = 0;
String test1, test2, test3;
test1 = getString(R.id.tvWeight);
test2 = getString(R.id.tvAge);
test3 = getString(R.id.tvHeight);
try {
if (test1 != "" && test2 != "" && test3 != "") {
Eweight = (EditText) findViewById(R.id.tvWeight);
weight = Integer.parseInt(Eweight.getText().toString().trim());
Eage = (EditText) findViewById(R.id.tvAge);
age = Integer.parseInt(Eage.getText().toString().trim());
Eheight = (EditText) findViewById(R.id.tvHeight);
height = Integer.parseInt(Eheight.getText().toString().trim());
if(gender.contains("Male"))
answer = (int) Math.round(1.2 * (66 + (13.7 * weight) + (5 * height) - (6.8 * age)));
if(gender.contains("Female"))
answer = (int) Math.round(1.2*(655 + (9.6 * weight) + (1.8 * height) - (4.7 * age)));
response = answer + " kcal/day";
counter.setText(response);
}
} catch (Exception e) {
System.out.println(e);
}
}
菜单窗口
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = getIntent();
intent.getStringExtra("response");
String answer = intent.getStringExtra(response);
}
});