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 ...
随机推荐
- UML:包图
什么是包图?包图是对UML图进行“打包”,按照你期望的方式进行组织的一种图.包图用于展示宏观上的内容.往往利用包图对类进行“打包”,但包图其实可以对任何UML图进行“打包”.包图是逻辑上的概念,你可以 ...
- Spring中Bean的配置:基于XML文件的方式
Bean的配置一共有两种方式:一种是基于XML文件的方式,另一种是基于注解的方式.本文主要介绍基于XML文件的方式 <bean id="helloWorld" class=& ...
- ajax常用参数
url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址.前台跳转到后台 请求参数:前台向后台传数据 回调函数:回调函数就是一个自定义的函数在发生特定的事件的时候调用来处理这个事件 ...
- C#Windows窗体应用程序MyKTV项目
后台管理其中有一个添加歌手信息和歌曲信息的窗体要点击按钮并上传文件,因为对那些文件流什么的不懂,所以用了老师教的最简单的判断方法,但此方法只是按后缀名判断文件的样式,如果后缀名乱改就不行了! 此时需要 ...
- HDU 4512 吉哥系列故事——完美队形(LCIS)
Problem Description 吉哥这几天对队形比较感兴趣. 有一天,有n个人按顺序站在他的面前,他们的身高分别是h[1], h[2] ... h[n],吉哥希望从中挑出一些人,让这些人形成一 ...
- /Users/alamps/AndroidStudioProjects/Demo10ScrollView
.define xml <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" andr ...
- php session memcache
ini_set("session.save_handler", "memcache"); ini_set("session.save_path&quo ...
- Android -- 初探MVP模式
1,相信大家对mvp模式都很熟悉了,M-Model-模型.V-View-视图.C-Controller-控制器.MVP作为MVC的版本演化,与MVC的意义类似:M-Model-模型.V-View-视图 ...
- cactive信号
AXI中C-channel的cactive信号并不仅仅应用在CSYSREQ,CSYSACK交互中. CSYSREQ和CSYSACK信号都在低电平表示lower power的请求和应答有效. cacti ...
- Cloudera CDH 、Impala本地通过Parcel安装配置详解
一.Parcel本地源与Package本地源的区别 本地通过Parcel安装过程与本地通过Package安装过程完全一致,不同的是两者的本地源的配置. 区别如下: Package本地源:软件包是.rp ...