存储登录

Posted storm47

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了存储登录相关的知识,希望对你有一定的参考价值。

<?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

以上是关于存储登录的主要内容,如果未能解决你的问题,请参考以下文章

如何将代码片段存储在 mongodb 中?

无法通过使用 Volley 库中的 Intent 从片段中移动下一个 Activity

如何将 r ggplot 图存储为 html 代码片段

sql 这些代码片段将演示如何逐步使用PolyBase。你应该有一个blob存储和存储秘密方便

从片段调用 Google Play 游戏服务

Facebook状态回调不适用于片段