下面提供的代碼中的朋友,我希望從遊戲意圖恢復時刷新我的文本視圖。但每當我嘗試定義我的TextView出OnCreate但在我的主類(在靜態int分數後),我的應用程序崩潰。在恢復主要活動時更新TextView
public class MainProjectActivity extends Activity {
/** Called when the activity is first created. */
static int Score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Display Scores
final TextView displayScores = (TextView)findViewById(R.id.scoreDisplay);
displayScores.setText("Your Score : "+ Score);
//Play Game button activity
Button gameButton = (Button)findViewById(R.id.PlayButton);
gameButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent play = new Intent(getApplicationContext(), com.sample.game.PlayScreen.class);
startActivity(play);
}
});
添加了刷新 – marmor