所以我设法进行了涉及 4 个变量的 4 个不同的活动,并以这种格式编写它们:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_step1);
Button c = (Button) this.findViewById(R.id.continue1);
final EditText input = (EditText) findViewById(R.id.enterscore);
input.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String score1 = input.getText().toString();
Double.parseDouble(score1);
{ Intent myintent = (new Intent(step1.this,step2.class));
myintent.putExtra("SCORE1",score1);
startActivity(myintent);
}
在我的最后一项活动中,假设显示解决方案的活动我编写了以下代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_answer);
}
public void solutionf(View v) {
Bundle extras = getIntent().getExtras();
if(extras!=null){
double score1 = extras.getDouble("SCORE1");
double score2 = extras.getDouble("SCOREF");
double l2 = extras.getDouble("L2");
double l3= extras.getDouble("L3");
double solution= (((score2-score1)/l2)*l3);
String resultString = "Result:" +solution;
TextView resultText= (TextView) findViewById(R.id.solution);
resultText.setText(resultstring);
}
}
}
为什么不显示最终解决方案?我已经检查过,以确保一切都与活动中设置的双打相匹配。难道是我没有通过我的代码错误正确地将变量从以前的活动中带过来吗?
任何帮助显示解决方案将不胜感激!