私はsharedPreferencesで最高のスコアを保存しようとしていますが、問題が発生しています。私は最高のスコアを出してそれを表示するように設定する方法を私は知らない。共有設定でハイスコアを表示しますか?
私が今行っているのは、プレーヤーが受け取った現在のスコアのみが表示されます。ここで私は今のところそのdoesntの仕事を持っているものである。このことにより、
public class GameOptions extends Activity {
int theScore;
TextView highScore;
public static String filename = "MyHighScore";
SharedPreferences spHighScore;
int dataReturned;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.in_game_menu);
TextView tvTheScore = (TextView) findViewById(R.id.textView2);
TextView highScore = (TextView) findViewById(R.id.high_score);
Bundle gotScore = getIntent().getExtras();
theScore = gotScore.getInt("scoreKey");
//String thisIsTheScoreToDisplay = theScore.toString();
tvTheScore.setText("SCORE: "+theScore);
spHighScore = getSharedPreferences(filename, 0);
SharedPreferences.Editor editor = spHighScore.edit();
editor.putInt("highScoreKey", theScore);
editor.commit();
int dataReturned = spHighScore.getInt("highScoreKey", 0);
highScore.setText("" + dataReturned);
btwこれはゲーム用であり、私はちょうどintである#1トップスコアだけを保存しようとしています。助けてくれてありがとう。 – alexward1230