0
私は非常に奇妙な問題があります。そして、私は3時間から4時間の間、解決策を求めるだけでなく、何も解決しません。私は "QuestionAsked"文字列に変数を格納していますが、他のすべての文字列が同じ値を示す理由はわかりません。 「QuestionAskedが」40とRecordQuestionAsked()
が呼び出されたされた場合SharedPreferencesが1つの変数を変更すると、他の人にも影響があります。
すなわち、今「QuestionAsked」が、この呼び出し後に作成されたすべての他にも、文字列「XYZ」だけではなく、問題になる可能性がどのような41 :(が表示されます?
private void RecordQuestionAsked(){
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
int prev = sharedPref.getInt(getString(R.string.QuestionAsked),0);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.QuestionAsked), prev+1);
editor.commit();
}
if (id == R.id.menuProg) {
if(ll1.getVisibility()==View.VISIBLE) {
ll1.setVisibility(View.GONE);
ll3.setVisibility(View.VISIBLE);
SharedPreferences sharedPref = getPreferences(Context.MODE_PRIVATE);
int ca = sharedPref.getInt(getString(R.string.xyz),1);
int qa = sharedPref.getInt(getString(R.string.QuestionAsked),0);
pba.setProgress(ca/qa*100);
pbi.setProgress((qa-ca)/qa*100);
txtProg.setText("Correct Answers/Total Questions : " + ca + "/" + qa);
}
}