score1の値によってhighScore1_110の値を変更したいです。10の値は0のまま変更されていません。
それをHighScoreClassで使用したいのですが、今の状態だとscore1の値にかかわらずhighScore1_1
Preferncesの手順がおかしいのでしょうか?
public class Result extends AppCompatActivity { int highScore1_1; int highScore1_2; int highScore1_3; int highScore1_4; int highScore1_5; int highScore1_6; int highScore1_7; int highScore1_8; int highScore1_9; int highScore1_10 ; int highScore2_1; int highScore2_2; int highScore2_3; int highScore2_4; int highScore2_5; int highScore2_6; int highScore2_7; int highScore2_8; int highScore2_9; int highScore2_10; int highScore3_1; int highScore3_2; int highScore3_3; int highScore3_4; int highScore3_5; int highScore3_6; int highScore3_7; int highScore3_8; int highScore3_9; int highScore3_10; boolean back; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_result); Intent intent = getIntent(); int score1 = intent.getIntExtra(Game1.SCORE, 0); int score2 = intent.getIntExtra(Game2.SCORE2, 0); long score3 = intent.getLongExtra(Game3.SCORE3, 0); if (score1 != 0) { TextView result = (TextView) findViewById(R.id.resultScore); result.setText(String.valueOf(score1)); } else if (score3 != 0) { TextView result = (TextView) findViewById(R.id.resultScore); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("mm:ss.SSS", Locale.US); result.setText(simpleDateFormat.format(score3)); } else { TextView result = (TextView) findViewById(R.id.resultScore); result.setText(String.valueOf(score2)); } SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(Result.this); highScore1_1 = preferences.getInt("highscore1_1", 0); highScore1_2 = preferences.getInt("highscore1_2", 0); highScore1_3 = preferences.getInt("highscore1_3", 0); highScore1_4 = preferences.getInt("highscore1_4", 0); highScore1_5 = preferences.getInt("highscore1_5", 0); highScore1_6 = preferences.getInt("highscore1_6", 0); highScore1_7 = preferences.getInt("highscore1_7", 0); highScore1_8 = preferences.getInt("highscore1_8", 0); highScore1_9 = preferences.getInt("highscore1_9", 0); highScore1_10 = preferences.getInt("highscore1_10", 0); if (highScore1_1 < score1) { highScore1_10 = highScore1_9; highScore1_9 = highScore1_8; highScore1_8 = highScore1_7; highScore1_7 = highScore1_6; highScore1_6 = highScore1_5; highScore1_5 = highScore1_4; highScore1_4 = highScore1_3; highScore1_3 = highScore1_2; highScore1_2 = highScore1_1; highScore1_1 = score1; } else if (highScore1_2 < score1 && score1 <= highScore1_1) { highScore1_10 = highScore1_9; highScore1_9 = highScore1_8; highScore1_8 = highScore1_7; highScore1_7 = highScore1_6; highScore1_6 = highScore1_5; highScore1_5 = highScore1_4; highScore1_4 = highScore1_3; highScore1_3 = highScore1_2; highScore1_2 = score1; } else if (highScore1_3 < score1 && score1 <= highScore1_2) { highScore1_10 = highScore1_9; highScore1_9 = highScore1_8; highScore1_8 = highScore1_7; highScore1_7 = highScore1_6; highScore1_6 = highScore1_5; highScore1_5 = highScore1_4; highScore1_4 = highScore1_3; highScore1_3 = score1; }else if (highScore1_4 < score1 && score1 <= highScore1_3){ highScore1_10 = highScore1_9; highScore1_9 = highScore1_8; highScore1_8 = highScore1_7; highScore1_7 = highScore1_6; highScore1_6 = highScore1_5; highScore1_5 = highScore1_4; highScore1_4 = score1; }else if (highScore1_5 < score1 && score1 <= highScore1_4){ highScore1_10 = highScore1_9; highScore1_9 = highScore1_8; highScore1_8 = highScore1_7; highScore1_7 = highScore1_6; highScore1_6 = highScore1_5; highScore1_5 = score1; }else if (highScore1_6 < score1 && score1 <= highScore1_5){ highScore1_10 = highScore1_9; highScore1_9 = highScore1_8; highScore1_8 = highScore1_7; highScore1_7 = highScore1_6; highScore1_6 = score1; }else if (highScore1_7 < score1 && score1 <= highScore1_6){ highScore1_7 = score1; highScore1_8 = highScore1_7; highScore1_9 = highScore1_8; highScore1_10 = highScore1_9; }else if (highScore1_8 < score1 && score1 <= highScore1_7){ highScore1_9 = highScore1_8; highScore1_10 = highScore1_9; highScore1_8 = score1; }else if (highScore1_9 < score1 && score1 <= highScore1_8){ highScore1_10 = highScore1_9; highScore1_9 = score1; }else if (highScore1_10 < score1 && score1 <= highScore1_9){ highScore1_10 = score1; } SharedPreferences.Editor editor = preferences.edit(); editor.putInt("highscore1_1", highScore1_1); editor.putInt("highscore1_2", highScore1_2); editor.putInt("highscore1_3", highScore1_3); editor.putInt("highscore1_4", highScore1_4); editor.putInt("highscore1_5", highScore1_5); editor.putInt("highscore1_6", highScore1_6); editor.putInt("highscore1_7", highScore1_7); editor.putInt("highscore1_8", highScore1_8); editor.putInt("highscore1_9", highScore1_9); editor.putInt("highscore1_10", highScore1_10); editor.commit(); } コード
public class HighScore extends AppCompatActivity { int highScore1_1; int highScore1_2; int highScore1_3; int highScore1_4; int highScore1_5; int highScore1_6; int highScore1_7; int highScore1_8; int highScore1_9; int highScore1_10; int highScore2_1; int highScore2_2; int highScore2_3; int highScore2_4; int highScore2_5; int highScore2_6; int highScore2_7; int highScore2_8; int highScore2_9; int highScore2_10; int highScore3_1; int highScore3_2; int highScore3_3; int highScore3_4; int highScore3_5; int highScore3_6; int highScore3_7; int highScore3_8; int highScore3_9; int highScore3_10; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_high_score); SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); highScore1_1 = preferences.getInt("highscore1_1", 0); highScore1_2 = preferences.getInt("highscore1_2", 0); highScore1_3 = preferences.getInt("highscore1_3", 0); highScore1_4 = preferences.getInt("highscore1_4", 0); highScore1_5 = preferences.getInt("highscore1_5", 0); highScore1_6 = preferences.getInt("highscore1_6", 0); highScore1_7 = preferences.getInt("highscore1_7", 0); highScore1_8 = preferences.getInt("highscore1_8", 0); highScore1_9 = preferences.getInt("highscore1_9", 0); highScore1_10 = preferences.getInt("highscore1_10", 0); TextView highScore1 = (TextView)findViewById(R.id.highScore1); TextView highScore2 = (TextView)findViewById(R.id.highScore2); TextView highScore3 = (TextView)findViewById(R.id.highScore3); TextView highScore4 = (TextView)findViewById(R.id.highScore4); TextView highScore5 = (TextView)findViewById(R.id.highScore5); TextView highScore6 = (TextView)findViewById(R.id.highScore6); TextView highScore7 = (TextView)findViewById(R.id.highScore7); TextView highScore8 = (TextView)findViewById(R.id.highScore8); TextView highScore9 = (TextView)findViewById(R.id.highScore9); TextView highScore10 = (TextView)findViewById(R.id.highScore10); highScore1.setText(String.valueOf(highScore1_1)); highScore2.setText(String.valueOf(highScore1_2)); highScore3.setText(String.valueOf(highScore1_3)); highScore4.setText(String.valueOf(highScore1_4)); highScore5.setText(String.valueOf(highScore1_5)); highScore6.setText(String.valueOf(highScore1_6)); highScore7.setText(String.valueOf(highScore1_7)); highScore8.setText(String.valueOf(highScore1_8)); highScore9.setText(String.valueOf(highScore1_9)); highScore10.setText(String.valueOf(highScore1_10)); } } コード
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/09/08 08:41
2016/09/08 08:51