安卓中的简单操作文件(登陆界面)
2015-09-01 15:45
330 查看
RwInRom.java
activity_main.xml
结果预览:
package com.ststudy.rwInRow; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; import android.widget.Toast; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; /** * Created by aaron on 9/1/15. */ public class RwInRom extends Activity { private EditText mEtName = null; private EditText mEtPassWord = null; private CheckBox mCbRe = null; private Button mBtLogin = null; private File mFile = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFile = new File("/data/data/com.ststudy.rwInRow/test"); login(); } public void login() { mEtName = (EditText) findViewById(R.id.etName); mEtPassWord = (EditText) findViewById(R.id.etPassWord); mCbRe = (CheckBox) findViewById(R.id.cbRe); mBtLogin = (Button) findViewById(R.id.btLogin); mBtLogin.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { // 获取用户名和密码 String _name = mEtName.getText().toString(); String _password = mEtPassWord.getText().toString(); if (mCbRe.isChecked()) { try { FileOutputStream _fos = new FileOutputStream(mFile); _fos.write((_name + "##" + _password).getBytes()); _fos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } Toast.makeText(RwInRom.this,"登陆成功",Toast.LENGTH_SHORT).show(); // Log.v("Login","登陆成功"); } }); } }
activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <EditText android:id="@+id/etName" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入用户名"/> <EditText android:id="@+id/etPassWord" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputType="textPassword" android:hint="请输入密码"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <CheckBox android:id="@+id/cbRe" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerVertical="true" android:text="下次自动登陆"/> <Button android:id="@+id/btLogin" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:text="登陆"/> </RelativeLayout> </LinearLayout>
结果预览:
相关文章推荐
- oracle10g logmnr 详细配置
- 反射方法实例
- linux下拉取文件的方法
- 面试题31.连续子数组的最大和
- C语言,realloc
- (转)浅析CSS——元素重叠及position定位的z-index顺序
- Android-编程小问题记录
- SQL SERVER 生成表结构的语句
- 探索 Pexpect,第 2 部分:Pexpect 的实例分析
- swift开发
- Assertion in void __stdcall mwJavaAbort(void)
- Objective-C学习笔记二:面向对象概述
- sqlserver 取10到20条
- display:table、box和width百分比来均分盒子的比较
- Linux串口编程教程(一)——基础知识介绍
- Android手势监听
- 两个链表的第一个公共结点-输入两个链表,找出它们的第一个公共结点。
- MyEclipse 8.5 Axis2 插件完整jar包
- Ubuntu Server 将环境变量修改为英文,防止中文乱码
- DOS批处理