1.定义sp
private SharedPreferences sp = null;
2.在oncreate函数中
sp = this.getSharedPreferences("userinfo", Context.MODE_PRIVATE);
if (sp.getBoolean("auto", false))
{
ed_username.setText(sp.getString("uname", null));
ed_pw.setText(sp.getString("upswd", null));
auto.setChecked(true);
}
3.判断checkbox是否选中
//记住密码
boolean autoLogin = auto.isChecked();
if (autoLogin)
{
Editor editor = sp.edit();
editor.putString("uname", _username);
editor.putString("upswd", _pw);
editor.putBoolean("auto", true);
editor.commit();
}
else
{
Editor editor = sp.edit();
editor.putString("uname", null);
editor.putString("upswd", null);
editor.putBoolean("auto", false);
editor.commit();
}