即時通訊創建一個高分但是我的問題是我不能在我的levelcomplete.class的按鈕中創建一個settext到我的highscore.class中。我的觀點是我想,如果我的高分(按鈕)是從我的levelcomplete.class點擊它將有一個textview settext自動在我的highscore.classsettext to highscore form other class
我的解釋流程levelcomplete.class = highscore(button)= highscore。類=的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);
}
});
}
}
highscore.class
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
}
}
你能用你的代碼編輯我的代碼嗎?哈哈哈它給我錯誤 – nice
這個邏輯編碼爲您的代碼。只需要瞭解邏輯。這看起來很難,但它非常簡單。在抓住要點之後,您將在複雜的應用程序中使用3.示例。 – Twinsens
公共類highscore擴展活動實現MyHighScoreClickListener { 我在MyHighScoreClickListener的錯誤 – nice