ハイスコアを持つゲームを作成していますが、私の問題は、レベルコンプリート.クラスのボタンからハイスコア.クラスにセットテキストを作成できないことです。私の要点は、レベルコンプリート.クラスからハイスコア(ボタン)をクリックすると、ハイスコア.クラスにテキストビューが自動的に設定されることです。
私の説明の流れ levelcomplete.class = highscore(button) = highscore.class = settext 10/10
スコアをハイスコアに保存するのと同じように
levelcomplete.class
public class levelcomplete extends Activity {
Button highscore;
int highestScore;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// TODO Auto-generated method stub
highscore = (Button) findViewById(R.id.save);
highscore.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Pass your score to other activity through Android's intent.
Intent intent = new Intent(getApplicationContext(),
highscore.class);
//THis highestScore variable will actually hold the score you get in this activity.
intent.putExtra("score", highestScore);
startActivity(intent);
}
});
}
}
ハイスコア.クラス
public class highscore extends Activity {
TextView score;
Button back;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.highscore);
score = (TextView) findViewById(R.id.score);
int highestScore = -1;
//Now use this score variable to set anywhere.
Bundle extras = getIntent().getExtras();
if (extras != null) {
highestScore = extras.getInt("score");
}
back = (Button) findViewById(R.id.btn_back);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(),"Back",
Toast.LENGTH_SHORT).show();
}
});
// TODO Auto-generated method stub
}
}