제가 작업하고있는 작은 게임이 있는데, 점수를 업데이트하는 중일뿐입니다. 제대로 작동하지 않습니다.Android SharedPreferences가 작동하지 않는 것 같습니다.
참고 : 여기에 표시 할 프로그램 조각을 잘라내어 설정중인 다른 것들이 많이 있습니다. 그러나 "점수"를 전혀 건드리지 않습니다. 그 이유는 코드가 작은 속기.
내 코드 :
public class Start_Test extends Activity {
TextView total_points;
long new_total;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three);
total_points = (TextView) findViewById(R.id.points);
SharedPreferences pref = getSharedPreferences("Prefs",
Context.MODE_PRIVATE);
new_total = pref.getLong("total_points", 0);
setTouchListener();
updateTotal(0);
}
public void updateTotal(long change_in_points) {
SharedPreferences pref = getSharedPreferences("Prefs",
Context.MODE_PRIVATE);
new_total = new_total + change_in_points;
pref.edit().putLong("total_points", new_total);
pref.edit().commit();
total_points.setText("" + new_total);
}
public void setTouchListeners() {
button.setOnTouchListener(new OnTouchListener() {
SharedPreferences pref = getSharedPreferences("Prefs",
Context.MODE_PRIVATE);
@Override
public boolean onTouch(View v, MotionEvent event) {
updateTotal(25);
return false;
}
});
}
아로 변경
. 아주 간단합니다. 내가 그랬다는 것을 믿을 수 없다. 모든 "put"문장을 다시 작성하겠습니다. ** 편집 : ** 방금 해봤습니다. 그것은 효과가있다! 감사! 내가 받아 들일 때까지 6 분. ㅎ. – EGHDK
@EGHDK : p 적어도 다음에 알거야 :) – Doomsknight