f(a, def, c) //Where def would mean default.
问题发生在受精后。 Android Studio with intent to other activities (原始代码)
[SecondActivity]
intent.putExtra ( "result", (double) kg / (Math.pow (tall, 2)) / 10000);// <SecondActivity>
result = intent.getDoubleExtra double ("result", 0); //<ThirdActivity>
I have tried the following:
tall: 150 cm
kg: 50kg
result: 1.95 .... (original calculations. 19.5)
Even if the value does not appear 10 Multiply.
}
[ThridActivity]
public class SecondActivity extends Activity {
RadioGroup rg;
ImageButton button4;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
rg = (RadioGroup) findViewById(R.id.radioGroup);
button4 = (ImageButton) findViewById(R.id.button4);
button4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RadioButton rd = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
//String str_Qtype = rd.getText().toString();
EditText et1 = (EditText) findViewById(R.id.EditText02); // tall (inot typing error)
EditText et2 = (EditText) findViewById(R.id.EditText01); // kg (not typing error)
int tall = Integer.parseInt(et1.getText().toString());
int kg = Integer.parseInt(et2.getText().toString());
Intent intent = new Intent(SecondActivity.this, ThirdActivity.class);
intent.putExtra("tall", Integer.parseInt(et1.getText().toString()));
intent.putExtra("kg", Integer.parseInt(et2.getText().toString()));
intent.putExtra("result",(double)kg/(Math.pow(tall,2))/10000);
startActivity(intent);
}
});
}
答案 0 :(得分:0)
要保存该值,请执行以下操作:
intent.putExtra("result",(float) (kg/((tall*0.01)*(tall*0.01))) ); // tall in cm unit
您需要获得float
值或另存为int
:
float result = intent.getFloatExtra("result", 0f);
[编辑] - 修正码错误
答案 1 :(得分:0)
在第二个活动中,您将结果存储在变量tall中,kg创建第三个变量结果并将该变量传递给方法
@Override
public void onClick(View v) {
RadioButton rd = (RadioButton) findViewById(rg.getCheckedRadioButtonId());
//String str_Qtype = rd.getText().toString();
EditText et1 = (EditText) findViewById(R.id.EditText02); // tall (inot typing error)
EditText et2 = (EditText) findViewById(R.id.EditText01); // kg (not typing error)
int tall = Integer.parseInt(et1.getText().toString());
int kg = Integer.parseInt(et2.getText().toString());
float result = kg/(tall*0.1)*(tall*0.1))
Intent intent = new Intent(SecondActivity.this, ThirdActivity.class);
intent.putExtra("tall", tall);
intent.putExtra("kg", kg);
intent.putExtra("result",result);
startActivity(intent);
和第三项活动
float result = intent.getFloatExtra("result",0);