Android简单数据存储类SharedPreferences详解及实例
2010-10-22 07:57:33 来源:WEB开发网super.onCreate(savedInstanceState);
setContentView(R.layout.login);
etAccount = (EditText) findViewById(R.id.etaccount);
etPW = (EditText) findViewById(R.id.etpw);
cbrp = (CheckBox) findViewById(R.id.cbrp);
cbal = (CheckBox) findViewById(R.id.cbal);
btnLogin = (Button) findViewById(R.id.btnlogin);
btnExit = (Button) findViewById(R.id.btnexit);
tvClear=(TextView)findViewById(R.id.tvclear);
InitConfig();
cbrp
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
sp = getSharedPreferences("UserInfo", 0);
sp.edit().putBoolean("cbrp", isChecked).commit();
}
});
cbal
.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
sp = getSharedPreferences("UserInfo", 0);
sp.edit().putBoolean("cbal", isChecked).commit();
}
});
btnLogin.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
user = new User(etAccount.getText().toString(), etPW.getText()
.toString());
Log.i("tag", "Account:" + etAccount.getText().toString());
Log.i("tag", "Password:" + etPW.getText().toString());
userMgr = new UserMgr();
Boolean flag = userMgr.CheckUser(user, Login.this);
if (!flag) {
Toast.makeText(Login.this, "用户验证错误!", 1000).show();
}
else {
if (cbrp.isChecked()) {
sp = getSharedPreferences("UserInfo",
Context.MODE_WORLD_WRITEABLE
| Context.MODE_WORLD_READABLE);
更多精彩
赞助商链接