登录layout
注册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