开发者

Load sharedpreferences not giving me a value

Here is my code.

        SharedPreferences sharedPreferences = getSharedPreferences(values,
            MODE_PRIVATE);
    str1开发者_如何学Python = sharedPreferences.getString("lu121", "test");
    str2 = sharedPreferences.getString("lp5151", "test");
    et_username.setText(str1);
    et_pass.setText(str2);

by default str1 and str2 should have values of test but when i open the android application the edittexts are not set as test instead i see a blank. Is there something wrong with my code?


You need to call commit() to save the values (you didn't include any code where you are writing.

...
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("lu", "testlu");
editor.putString("lp", "testlp");
editor.commit();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜