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(登录记住)的更多相关文章

  1. Android SharedPreferences登录记住密码

    SharedPreferences是Android中存储简单数据的一个工具类.可以想象它是一个小小的Cookie,它通过用键值对的方式把简单 数据类型(boolean.int.float.long和S ...

  2. 【转】Xamarin.Android 入门之:Xamarin+vs2015 环境搭建

    Xamarin.Android 入门之:Xamarin+vs2015 环境搭建   一.前言 此篇博客主要写了如何使用搭建xamarin开发的环境,防止我自己万一哪天电脑重装系统了,可以直接看这篇博客 ...

  3. android 注册、登录实现程序

    注册页面: user_register.xml: <?xml version="1.0" encoding="utf-8"?> <Linear ...

  4. 小猪的Android入门之路 Day 7 part 2

    小猪的Android入门之路 Day 7 part 2 Android的数据存储与訪问之--SharedPreferences(保存偏好參数) ---转载请注明出处:coder-pig 本节引言: 在 ...

  5. Android精通教程-第一节Android入门简介

    前言 大家好,给大家带来Android精通教程-第一节Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cease to be ...

  6. Android精通教程-Android入门简介

    前言 大家好,我是 Vic,今天给大家带来Android精通教程-Android入门简介的概述,希望你们喜欢 每日一句 If life were predictable it would cease ...

  7. Android 微信第三方登录(个人笔记)

    今天在写微信登录,花了半天时间搞定.然后写下自己的笔记,希望帮助更多的人...欢迎各位指教. 微信授权登录,官方说的不是很清楚.所以导致有一部分的坑. 微信注册应用平台的应用签名,下载 微信签名生成工 ...

  8. Android入门(十二)SQLite事务、升级数据库

    原文链接:http://www.orlion.ga/610/ 一.事务 SQLite支持事务,看一下Android如何使用事务:比如 Book表中的数据都已经很老了,现在准备全部废弃掉替换成新数据,可 ...

  9. android 入门 006(sqlite增删改查)

    android 入门 006(sqlite增删改查) package cn.rfvip.feb_14_2_sqlite; import android.content.Context; import ...

随机推荐

  1. URAL 1018 Binary Apple Tree(树DP)

    Let's imagine how apple tree looks in binary computer world. You're right, it looks just like a bina ...

  2. C#写好的类库dll怎么在别人调用的时候也能看到注释?

    菜单 Project -> 'xxxx' Properties -> Build -> Output -> 勾上 XML Documentation file

  3. paper 38 :entropy

    图像熵计算 真是为了一个简单的基础概念弄的心力交瘁,请教了一下师姐,但是并没有真的理解,师弟我太笨呀~~所以,我又查熵的中文含义和相关的出处!共勉吧~~ 1.信息熵: 利用信息论中信息熵概念,求出任意 ...

  4. 机器学习(Machine Learning)&深入学习(Deep Learning)资料

    <Brief History of Machine Learning> 介绍:这是一篇介绍机器学习历史的文章,介绍很全面,从感知机.神经网络.决策树.SVM.Adaboost 到随机森林. ...

  5. CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页。

    CSS(Cascading Style Sheet,叠层样式表),作用是美化HTML网页. /*注释区域*/    此为注释语法 一.样式表 (一)样式表的分类 1.内联样式表 和HTML联合显示,控 ...

  6. [经典php视频]构建正则表达式解析网页中的图像标记<img>

    这是高洛峰php视频中的一段,视频中一边分析需要的功能,一边构建greg_match函数的参数,边讲解边实战,是非常好的一种构建功能的演示. 你不可能把浩瀚的IT资料都记在脑袋里,也不可能随时随地透过 ...

  7. DELPHI出现无法加载dclite50.bpl的解决办法(转)

    现象: Borland Integrated Translation Environment 加载出错 解决办法: 我的电脑--->(鼠标右键)属性--->高级--->(性能)设置- ...

  8. Gson将参数放入实体类中进行包装之后再传递

    package com.sinoservices.dms.orderinfo.entity; public class OrderDetailKeyCondition { //工单主键 private ...

  9. 161019、并发容器ConcurrentHashMap

    java.util.concurrent.ConcurrentMap<K, V>一种是用读写锁实现Map的方法.此种方法看起来可以实现Map响应的功能,而且吞吐量也应该不错.但是通过前面对 ...

  10. iOS使用静态变量

    之前看"Effective Objective-C 2.0", 第4条, 多用静态变量, 少用define. 正好我的项目有些东西是静态变量, 之前java我习惯起一个类, 里面全 ...