Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Last active October 21, 2018 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/e0a28bb2f7aeee297ed56517c33a99d9 to your computer and use it in GitHub Desktop.
Save codingwithsara/e0a28bb2f7aeee297ed56517c33a99d9 to your computer and use it in GitHub Desktop.
7-3
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
TextView resultLabel = findViewById(R.id.resultLabel);
TextView totalScoreLabel = findViewById(R.id.totalScoreLabel);
// 正解数を取得
int score = getIntent().getIntExtra("RIGHT_ANSWER_COUNT", 0);
// トータルスコアの読み出し
SharedPreferences prefs = getSharedPreferences("quizApp", Context.MODE_PRIVATE);
int totalScore = prefs.getInt("totalScore", 0);
// トータルスコアに今回のスコアを加算
totalScore += score;
// TextViewに表示する
resultLabel.setText(score + " / 5");
totalScoreLabel.setText("トータルスコア : " + totalScore);
// トータルスコアを保存
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("totalScore", totalScore);
editor.apply();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment