WEB开发网
开发学院手机开发Android 开发 Android简单数据存储类SharedPreferences详解及实... 阅读

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);

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);

上一页  1 2 3 4 5 6  下一页

Tags:Android 简单 数据

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接