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 ...
随机推荐
- extjs实现简单的多文件上传(不借助任何插件),以及包含处理上传大文件的错误的各种处理办法
在extjs的学习过程中,有遇到过有关多文件上传的问题,但是网上的大多数都是专门的去实现多文件上传而去做的组件之类的,没有特别简单的方式,于是小白便做了下面的内容,只是通过动态的去添加extjs的自带 ...
- Android中使用SurfaceView+MediaPlayer+自定义的MediaController实现自定义的视屏播放器
效果图如下: (PS本来是要给大家穿gif动态图的,无奈太大了,没法上传) 功能实现:暂停,播放,快进,快退,全屏,退出全屏,等基本功能 实现的思路: 在主布局中放置一个SurfaceView,在Su ...
- java mvc控制器基本传值方式
控制器----- @RequestMapping(value = "MatchDetail", method = RequestMethod.GET) public ModelAn ...
- User Managerment 职责不能使用的问题
1.此职责默认的是没有启用授权的(grant),需要在系统管理员职责下搜索到对应的菜单,进行grant 2.就算授权后,用户还是不能进行操作,需要进行以下设置: 1. Log into the app ...
- 解决ultravnc在win2008 R2下CTRL+ALT+DELETEA组合键发送失败的问题
首先,请google “ultravnc ctrl+alt+delete”,得到的解决方法是,更改UAC.进入组策略-计算机配置-管理模板-windows登陆选项,“禁用或启用软件注意序列”,更改成“ ...
- NOIP201402比例化简
比例化简 [问题描述]在社交媒体上,经常会看到针对某一个观点同意与否的民意调查以及结果.例如,对某一观点表示支持的有 1498 人,反对的有 902 人,那么赞同与反对的比例可以简单的记为1498:9 ...
- 5 Best Automation Tools for Testing Android Applications
Posted In | Automation Testing, Mobile Testing, Software Testing Tools Nowadays automated tests ar ...
- 鸟哥的linux私房菜学习记录之账号管理与权限设定
每个登录者都会取到两个ID,一个使用者ID,一个群组ID
- Hadoop三种安装模式:单机模式,伪分布式,真正分布式
Hadoop三种安装模式:单机模式,伪分布式,真正分布式 一 单机模式standalone单 机模式是Hadoop的默认模式.当首次解压Hadoop的源码包时,Hadoop无法了解硬件安装环境,便保守 ...
- WEB前端常用网站收集
WEB前端常用网站收集整理 w3school.w3schools 前端里.脚本之家.素材家园 17素材.frontopen NEC更好的CSS方案.一些常用的JS实例 Bootstrap 官网 h ...