如何将 textview 的值从一个活动传递到另一个活动?
我的游戏得分显示在 textview 上,并且在它增加后它将打算进行下一个活动。但是第一个活动的分数值没有显示在第二个活动的文本视图上。
这是我第一次活动的代码
final TextView score2 = (TextView) findViewById(R.id.tvscore2);
Button page1 = (Button) findViewById(R.id.btnDog);
page1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
EditText etDog1 = (EditText) findViewById(R.id.etDog);
String Dog = etDog1.getText().toString();
if (Dog.equalsIgnoreCase("dog")) {
global.score += 10;
score2.setText(String.valueOf(global.score));
Toast.makeText(getApplicationContext(), "Correct",
Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(view.getContext(),
sound1_3pig.class);
startActivityForResult(myIntent, 0);
} else if (global.score <= 0) {
global.score += 0;
score2.setText(String.valueOf(global.score));
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
} else {
global.score -= 5;
score2.setText(String.valueOf(global.score));
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
}
}
});
}
我想将分数活动 1 的结果显示到第二个活动的 textview
这是我的第二个活动
final TextView score1 = (TextView) findViewById(R.id.tvscore1);
Button page1 = (Button) findViewById(R.id.btnCat);
page1.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
EditText etCat = (EditText) findViewById(R.id.etCat);
String Cat = etCat.getText().toString();
if (Cat.equalsIgnoreCase("cat")) {
global.score += 10;
score2.setText(String.valueOf(global.score));
Toast.makeText(getApplicationContext(), "Correct",
Toast.LENGTH_SHORT).show();
Intent myIntent = new Intent(view.getContext(),
sound1_3pig.class);
startActivityForResult(myIntent, 0);
finish();
} else if (global.score <= 0) {
global.score += 0;
score2.setText(String.valueOf(global.score));
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
} else {
global.score -= 5;
score2.setText(String.valueOf(global.score));
Toast.makeText(getApplicationContext(), "Wrong",
Toast.LENGTH_SHORT).show();
}
}
});
}