存储
2016-05-23 16:13
218 查看
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.hanqi.zuoyee.cunchu_denglu"> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入账号" android:id="@+id/et1"/> <EditText android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center"> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:text="登录" android:onClick="b1"/> <Button android:layout_width="wrap_content" android:layout_height="match_parent" android:text="注册"/> </LinearLayout> </LinearLayout>
layout文件
package com.hanqi.zuoyee; import android.content.SharedPreferences; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.EditText; public class cunchu_denglu extends AppCompatActivity { EditText et; String zh; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_cunchu_denglu); et=(EditText)findViewById(R.id.et1); SharedPreferences s=getSharedPreferences("a",MODE_PRIVATE); zh=s.getString("zhanghao",null); if(zh!=null){ et.setText(zh); } } public void b1(View v){ SharedPreferences s=getSharedPreferences("a", MODE_PRIVATE); SharedPreferences.Editor editor = s.edit(); zh=et.getText().toString(); if(zh.trim().length()==0){ return; } editor.putString("zhanghao",zh); editor.commit(); } }
相关文章推荐
- Redis系列学习笔记14 微博功能分析
- 项目经理防雷记
- java中文乱码解决之道(6):javaWeb中的编码解码的
- Unity3d|5.3.4多场景编辑功能
- jQuery判断是否为正整数
- Mysql几种索引方式的区别及适用情况
- redis java 分页、排序示例
- warning和error的区别
- Android 应用程序发送shell命令
- UGUI研究院之开始学习搭建界面自适应屏幕
- Android图片下载机制
- sqlserver批量更新
- Redis系列学习笔记13 Lua 脚本
- GitHub Windows版本下载失败的解决方法
- tomcat(15)Digester库
- VBA进度条
- leetcode笔记--Best Time to Buy and Sell Stock系列(I,II, III, IV)
- JSON.stringify()、,JSON.eval(),JSON.parse()各自的区别于作用
- linux基础命令之权限管理命令
- Linux下定时执行脚本