-
-
Save codeforfun-jp/6d6af9a20d9a97bb666947e6a5eb1552 to your computer and use it in GitHub Desktop.
QuizApp 4.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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 = getPreferences(Context.MODE_PRIVATE); | |
int totalScore = prefs.getInt("TOTAL_SCORE", 0); | |
// トータルスコアに今回のスコアを加算 | |
totalScore += score; | |
// TextViewに表示する | |
resultLabel.setText(getString(R.string.result_score, score)); | |
totalScoreLabel.setText(getString(R.string.result_total_score, totalScore)); | |
// トータルスコアを保存 | |
SharedPreferences.Editor editor = prefs.edit(); | |
editor.putInt("TOTAL_SCORE", totalScore); | |
editor.apply(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment