android 入门 005(登录记住)
android 入门 005(登录记住)
<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" > <EditText
android:id="@+id/et_name" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入用户名"
/> <EditText
android:id="@+id/et_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="请输入密码" /> <RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" > <CheckBox
android:id="@+id/cb_rember"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_marginLeft="22dp"
android:text="记住" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_gravity="right"
android:text="登录"
android:onClick="login"
/>
</RelativeLayout> </LinearLayout>

2、java 代码
package cn.rfvip.login; import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader; import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.Toast; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
remberaccout();
} public void remberaccout() {
File file = new File("data/data/cn.rfvip.login/info1.txt");
try {
FileInputStream fis = new FileInputStream(file);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
String string_info = br.readLine();
String[] s = string_info.split("##");
EditText et_name = (EditText) findViewById(R.id.et_name);
EditText et_password = (EditText) findViewById(R.id.et_password);
et_name.setText(s[0]);
et_password.setText(s[1]);
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
}
} public void login(View v) {
EditText et_name = (EditText) findViewById(R.id.et_name); EditText et_password = (EditText) findViewById(R.id.et_password);
String string_et_name = et_name.getText().toString();
String string_et_password = et_password.getText().toString(); CheckBox cb_rember = (CheckBox) findViewById(R.id.cb_rember);
if (cb_rember.isChecked()) {
File file = new File("data/data/cn.rfvip.login/info1.txt");
FileOutputStream fos; try {
fos = new FileOutputStream(file);
fos.write((string_et_name + "##" + string_et_password)
.getBytes());
fos.close();
} catch (Exception e) {
// TODO 自动生成的 catch 块
e.printStackTrace();
} }
Toast.makeText(this, "登录成功!", 0).show();
Log.i("tag", "登录成功!");
// Toast.makeText(getApplicationContext(), "登录成功!",
// Toast.LENGTH_SHORT).show();
// Toast toast1 = Toast.makeText(getApplicationContext(),
// "自定义位置Toast", Toast.LENGTH_LONG);
// toast1.setGravity(Gravity.CENTER, 100, 100);
// toast1.show(); } }
效果:自动记住了

android 入门 005(登录记住)的更多相关文章
- Android SharedPreferences登录记住密码
SharedPreferences是Android中存储简单数据的一个工具类.可以想象它是一个小小的Cookie,它通过用键值对的方式把简单 数据类型(boolean.int.float.long和S ...
- 【转】Xamarin.Android 入门之:Xamarin+vs2015 环境搭建
Xamarin.Android 入门之:Xamarin+vs2015 环境搭建 一.前言 此篇博客主要写了如何使用搭建xamarin开发的环境,防止我自己万一哪天电脑重装系统了,可以直接看这篇博客 ...
- android 注册、登录实现程序
注册页面: user_register.xml: <?xml version="1.0" encoding="utf-8"?> <Linear ...
- 小猪的Android入门之路 Day 7 part 2
小猪的Android入门之路 Day 7 part 2 Android的数据存储与訪问之--SharedPreferences(保存偏好參数) ---转载请注明出处:coder-pig 本节引言: 在 ...
- Android精通教程-第一节Android入门简介
前言 大家好,给大家带来Android精通教程-第一节Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cease to be ...
- Android精通教程-Android入门简介
前言 大家好,我是 Vic,今天给大家带来Android精通教程-Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cease ...
- Android 微信第三方登录(个人笔记)
今天在写微信登录,花了半天时间搞定.然后写下自己的笔记,希望帮助更多的人...欢迎各位指教. 微信授权登录,官方说的不是很清楚.所以导致有一部分的坑. 微信注册应用平台的应用签名,下载 微信签名生成工 ...
- Android入门(十二)SQLite事务、升级数据库
原文链接:http://www.orlion.ga/610/ 一.事务 SQLite支持事务,看一下Android如何使用事务:比如 Book表中的数据都已经很老了,现在准备全部废弃掉替换成新数据,可 ...
- android 入门 006(sqlite增删改查)
android 入门 006(sqlite增删改查) package cn.rfvip.feb_14_2_sqlite; import android.content.Context; import ...
随机推荐
- EBS R12中重新enable失效用户之后,丢失职责
以下请求跑完不能立即生效,需要等上一段时间! oracle support说这并不是一个bug,是一个问题,呵呵,bug和问题,都是你的错,oracle! 工 作中将某个用户失效之后,有可能又需要重新 ...
- mybatis(一)安装
1.创建web项目,添加jar包 2.创建实验表user_t 3.在src下创建conf.xml文件,如下 <?xml version="1.0" encoding=&quo ...
- [Ubuntu] ubuntu13.04 从php5.4降级到php5.3
ubuntu12.10以后,默认的deb安装库上面的php版本已经是5.4了,公司的项目使用5.4的时候,还是会出现很多问题,所以不得不降级安装5.3 顺便说一句,我原来的环境是nginx + php ...
- C++代码段六
摘自<Primer Plus>浮点数优缺点: void test109() { float a=2.34E+22f; float b=a+1.0f; cout<<"a ...
- 【海岛帝国系列赛】No.6 海岛帝国:战争前线
50234237海岛帝国:战争前线 [试题描述] 总指挥官WHT出神入化的计谋虽然大有用武之地,但是聪明的恐怖分子们采取了城市核武器防御系统,可以有效地抵制WHT的炸弹.YSF对此头痛不已,因此 召开 ...
- Origin双坐标轴图表
1.空白处右键Add New Colume添加新列 2.全选各个列绘制图表 3.添加新的Y轴图层Graph—New Layer—Right-Y 4.右键左上角图层2 –Layer Contents 绑 ...
- WM_SIZE
procedure WMSize (var Message: TWMSize); message WM_SIZE; 参数说明 wParam: Specifies the type of resizin ...
- ch2-1:创建模块,并调用模块中的函数
模块就是一个包含python代码的文本文件,文件名以.py结尾,这是python扩展名: 1.创建一个模块nester.py,文件内容为: '''这是一个模块,可以打印列表,其中可能包含嵌套列表''' ...
- ubuntu硬件配置查看命令
主板:sudo dmidecode |grep -A16 "System Information$"
- 【JQGRID DOCUMENTATION】.学习笔记.3.Pager
处理大量数据时,一次只想显示一小部分.这时就需要Navigation Bar.目前Pager不能用于TreeGrid. 定义 }); 定义高度grid,pager是grid的一部分,宽度等于gird的 ...