• 存储登录


    <?xml version="1.0" encoding="utf-8"?>
    <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"
        tools:context="com.hanqi.zuoyee.cunchu2denglu">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入账号"
            android:id="@+id/et1"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入密码"
            android:id="@+id/et2"
           android:inputType="textPassword"
            />
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="登录"
                android:onClick="b1"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="注册"
                android:onClick="b2"/>
        </LinearLayout>
    
    
    </LinearLayout>

    登录layout

    <?xml version="1.0" encoding="utf-8"?>
    <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"
        tools:context="com.hanqi.zuoyee.cunchu2zhuce">
    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入账号"
        android:id="@+id/et1"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请输入密码"
            android:id="@+id/et2"
            android:inputType="textPassword"/>
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="请再次输入密码"
            android:id="@+id/et3"
            android:inputType="textPassword"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">
            <Button
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="返回"
                android:onClick="b1"/>
            <Button
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="确认注册"
                android:onClick="b2"/>
        </LinearLayout>
    </LinearLayout>

    注册layout

    package com.hanqi.zuoyee;
    
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    import android.support.v7.app.AppCompatActivity;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;
    
    public class cunchu2denglu extends AppCompatActivity {
        EditText et1,et2;
        String s1,s2;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.cunchu2denglu);
            et1=(EditText)findViewById(R.id.et1);
            et2=(EditText)findViewById(R.id.et2);
    
        }
        public  void b1(View v){
            s1=et1.getText().toString();
            s2=et2.getText().toString();
            if(s1.trim().length()==0){
                Toast.makeText(cunchu2denglu.this, "正确输入账号", Toast.LENGTH_SHORT).show();
            }
            String s11,s22;
            SharedPreferences s=getSharedPreferences("zhanghao",MODE_PRIVATE);
            s11=s.getString("zhanghao","");
            s22=s.getString("mima","");
            if(s11.trim().length()==0){
                Toast.makeText(cunchu2denglu.this, "请注册账号", Toast.LENGTH_SHORT).show();
                return;
            }
            if(!s11.equals(s1)){
                Toast.makeText(cunchu2denglu.this, "请正确输入账号", Toast.LENGTH_SHORT).show();
                Toast.makeText(cunchu2denglu.this, s1, Toast.LENGTH_SHORT).show();
                return;
            }
            if(!s2.equals(s22)){
                Toast.makeText(cunchu2denglu.this, "请正确输入密码", Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(cunchu2denglu.this, "登陆成功", Toast.LENGTH_SHORT).show();
            }
    
        }
        public  void b2(View v){
            Intent intent=new Intent(cunchu2denglu.this,cunchu2zhuce.class);
           startActivity(intent);
        }
    }

    登录java

    package com.hanqi.zuoyee;
    
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.EditText;
    import android.widget.Toast;
    
    public class cunchu2zhuce extends AppCompatActivity {
    EditText et1,et2,et22;
        String s1,s2,s22;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_cunchu2zhuce);
            et1=(EditText)findViewById(R.id.et1);
            et2=(EditText)findViewById(R.id.et2);
            et22=(EditText)findViewById(R.id.et3);
    
        }
        public void b1(View v){
            Intent intent=new Intent(cunchu2zhuce.this,cunchu2denglu.class);
            startActivity(intent);
        }
        public void b2(View v){
            s1=et1.getText().toString();
            s2=et2.getText().toString();
            s22=et22.getText().toString();
            if(s1.trim().length()==0){
                Toast.makeText(cunchu2zhuce.this, "请正确输入账号", Toast.LENGTH_SHORT).show();
                return;
            }
            if(s2.trim().length()==0){
                Toast.makeText(cunchu2zhuce.this, "请正确输入密码", Toast.LENGTH_SHORT).show();
                return;
            }
            if(!s2.equals(s22)){
                Toast.makeText(cunchu2zhuce.this, "两次密码输入不一致", Toast.LENGTH_SHORT).show();
                return;
            }
            SharedPreferences sp=getSharedPreferences("zhanghao",MODE_PRIVATE);
            SharedPreferences.Editor e=sp.edit();
            e.putString("zhanghao",s1);
            e.putString("mima", s2);
            e.commit();
            Toast.makeText(cunchu2zhuce.this, "注册成功", Toast.LENGTH_SHORT).show();
            Intent intent=new Intent(cunchu2zhuce.this,cunchu2denglu.class);
            startActivity(intent);
        }
    }

    注册java

  • 相关阅读:
    第15周作业
    软件工程结课作业
    第13次作业--邮箱的正则表达式
    第12次作业
    第10次作业
    Java 8 新的时间日期库
    你还在用if-else吗?
    Java并发编程:4种线程池和缓冲队列BlockingQueue
    ZooKeeper学习第八期——ZooKeeper伸缩性(转)
    ZooKeeper学习第七期--ZooKeeper一致性原理(转)
  • 原文地址:https://www.cnblogs.com/storm47/p/5533549.html
Copyright © 2020-2023  润新知