import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText; public class DengLu extends Activity implements OnClickListener{
private EditText name;
private EditText password;
private CheckBox box1;
private CheckBox box2;
private SharedPreferences sharedPreferences;
private Button button; @Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.denglu);
button = (Button) findViewById(R.id.button);
name = (EditText) findViewById(R.id.name);
password = (EditText) findViewById(R.id.password);
box1 = (CheckBox) findViewById(R.id.baocun);
box2 = (CheckBox) findViewById(R.id.zidong);
sharedPreferences = getSharedPreferences("zhuce", 0);
//记住密码
boolean isCheckBox1 =sharedPreferences.getBoolean("CheckBox1", false);
//自动登录
boolean isCheckBox2 =sharedPreferences.getBoolean("CheckBox2", false); String names=sharedPreferences.getString("name","");
String passwords=sharedPreferences.getString("password", ""); if(isCheckBox1){
if(!names.equals("")&&!passwords.equals("")){
name.setText(names);
password.setText(passwords);
box1.setChecked(true);
}else{
if(!names.equals("")){
name.setText(names);
}
} }
if(isCheckBox2){ Intent intent = new Intent(DengLu.this, ZhuYe.class);
startActivity(intent); }
button.setOnClickListener(this); } @Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.button:
if(box1.isChecked()){
sharedPreferences.edit().putBoolean("CheckBox1", true).commit();
sharedPreferences.edit().putString("name", name.getText().toString()).commit();
sharedPreferences.edit().putString("password", password.getText().toString()).commit(); }else{
sharedPreferences.edit().putBoolean("CheckBox1", false).commit();
sharedPreferences.edit().putString("name", name.getText().toString()).commit();
sharedPreferences.edit().putString("password", "").commit();
}
if(box2.isChecked()){
sharedPreferences.edit().putBoolean("CheckBox2", true).commit();
} Intent intent = new Intent(DengLu.this, ZhuYe.class);
startActivity(intent);
break; default:
break;
}
}
}

最新文章

  1. 对于新安装的MySQL如何提升MySQL的安全级别
  2. Javascript到PHP加密通讯的简单实现
  3. 常用Meta整理
  4. 深入理解web项目的配置文件
  5. jQuery Mobile里xxx怎么用呀?(缓存篇)
  6. preventDefault() 方法 取消掉与事件关联的默认动作
  7. js 对日期加减
  8. java基础,集合,HashMap,源码解析
  9. Redis 部署主从哨兵 C#使用,实现自动获取redis缓存 实例2
  10. C语言中sizeof与strlen区别
  11. Spring Aop分析
  12. POJ 2407Relatives
  13. MySQL数据库性能优化思路与解决方法(一转)
  14. JavaSE从入门到精通
  15. Remove Duplicates from Sorted ListII
  16. 深入JVM之类的加载过程
  17. express总结(一)
  18. PHP使用phpstorm进行断点调试
  19. CentOS yum 源的配置与使用(引用)
  20. 二叉树及其遍历方法---python实现

热门文章

  1. JS-002-修改元素属性(以按钮示例)
  2. Number类型
  3. saltstack之(十)扩展组件salt-ssh
  4. jQuery对象与DOM对象之间的转换(转)
  5. 查看mysql的版本
  6. nginx源码学习----内存池
  7. BI系统规划前需要准备的6项工作
  8. glusterFS安装维护文档
  9. UITableView + UISearchBar 实现搜索功能
  10. linux:主机规划和磁盘分割