安卓中的简单操作文件(登陆界面)

来源:互联网 发布:手机数据恢复大师官网 编辑:程序博客网 时间:2024/05/17 06:20

RwInRom.java

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>

结果预览:
这里写图片描述

0 0
原创粉丝点击