?设计界面
(一)界面一
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/f5dd641ccb24f73ac133c9ec6eb1ac7"
tools:context="com.example.jishiben.MainActivity">
<Button
android:id="@+id/button"
style="@style/Widget.AppCompat.Button.Small"
android:layout_width="142dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/transparent"
android:shadowColor="@android:color/background_light"
android:text="点这里!"
android:textColor="@android:color/black"
android:textColorHint="@android:color/background_light"
android:textSize="30sp"
android:textStyle="bold"
android:typeface="normal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.168"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.109" />
</android.support.constraint.ConstraintLayout>
(二)登录界面
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/f0b14ba475f4bd8c0a1995d9fd9affd"
tools:context="com.example.jishiben.LoginActivity">
<EditText
android:id="@+id/userpass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/darker_gray"
android:drawableLeft="@android:drawable/ic_secure"
android:ems="10"
android:hint="请输入密码"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.359"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.328" />
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/darker_gray"
android:drawableLeft="@android:drawable/ic_menu_myplaces"
android:ems="10"
android:hint="请输入账户"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.359"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.213" />
<TextView
android:id="@+id/t_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="忘记密码"
android:textColor="@android:color/background_light"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.185"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.492" />
<TextView
android:id="@+id/t_register"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="立即注册"
android:textColor="@android:color/background_light"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.766"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.492" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="#e9d8b9"
android:bufferType="spannable"
android:capitalize="words"
android:text="登录"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.467"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/userpass"
app:layout_constraintVertical_bias="0.598" />
</android.support.constraint.ConstraintLayout>
(三)用户注册界面
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/c72efbe1627452fbaa84f7669e6bb35"
tools:context="com.example.jishiben.RegisterActivity">
<TextView
android:id="@+id/textView6"
android:layout_width="66dp"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="性别"
android:textColor="@android:color/background_light"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.026"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.71" />
<TextView
android:id="@+id/textView5"
android:layout_width="66dp"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="民族"
android:textColor="@android:color/background_light"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.026"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.554" />
<TextView
android:id="@+id/textView4"
android:layout_width="82dp"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="确认密码"
android:textColor="@android:color/background_light"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.307" />
<TextView
android:id="@+id/textView3"
android:layout_width="66dp"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="密码"
android:textColor="@android:color/background_light"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.059"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.162" />
<EditText
android:id="@+id/edt_pssConfirm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.679"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.311" />
<EditText
android:id="@+id/edt_pss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.679"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.164" />
<EditText
android:id="@+id/edt_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.679"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.017" />
<TextView
android:id="@+id/textView2"
android:layout_width="66dp"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="用户名"
android:textColor="@android:color/background_light"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.059"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.032" />
<Spinner
android:id="@+id/spinner"
android:layout_width="135dp"
android:layout_height="43dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:entries="@array/minzu"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.523"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.559" />
<RadioButton
android:id="@+id/rd_female"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:drawableBottom="@android:drawable/btn_star"
android:text="女"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.611"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.729" />
<RadioButton
android:id="@+id/rd_male"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:drawableBottom="@android:drawable/btn_star_big_on"
android:text="男"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.401"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.729" />
<Button
android:id="@+id/btn_ok"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="确定"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.15"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView6"
app:layout_constraintVertical_bias="0.643" />
<Button
android:id="@+id/btn_login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="返回登录"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.338"
app:layout_constraintStart_toEndOf="@+id/btn_ok"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.939" />
</android.support.constraint.ConstraintLayout>
(四)用户忘记密码
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/l4140f5e7f2a329bb31d254a3d6fbfec"
tools:context="com.example.jishiben.ModifyPassActivity">
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="35dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="确认密码"
android:textColor="@android:color/background_light"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.639" />
<TextView
android:id="@+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="修改密码"
android:textColor="@android:color/background_light"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.025"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.457" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="39dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="原密码"
android:textColor="@android:color/background_light"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.024"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.337" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="用户名"
android:textColor="@android:color/background_light"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.028"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.172" />
<EditText
android:id="@+id/et_name"
android:layout_width="211dp"
android:layout_height="53dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.053"
app:layout_constraintStart_toEndOf="@+id/textView7"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.139" />
<EditText
android:id="@+id/et_oldpass"
android:layout_width="201dp"
android:layout_height="56dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.616"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.307" />
<EditText
android:id="@+id/et_newpass"
android:layout_width="208dp"
android:layout_height="56dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.455" />
<EditText
android:id="@+id/et_newpass1"
android:layout_width="215dp"
android:layout_height="63dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.67"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/et_name"
app:layout_constraintVertical_bias="0.58" />
<Button
android:id="@+id/bt_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/darker_gray"
android:text="查询密码"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.11"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.885" />
<Button
android:id="@+id/bt_modify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:background="@android:color/darker_gray"
android:text="修改密码"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.653"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.885" />
</android.support.constraint.ConstraintLayout>
代码在这~
(一)界面一——实现界面跳转
package com.example.jishiben;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MainActivity.this,LoginActivity.class);
startActivity(intent);
}
});
}
}
(二)登陆界面
package com.example.jishiben;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class LoginActivity extends AppCompatActivity implements View.OnClickListener{
private EditText username,userpass;
private TextView t_login,t_register;
private Button button;
private DBAdapter dbAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
t_register=findViewById(R.id.t_register);
t_login=findViewById(R.id.t_login);
username=findViewById(R.id.username);
userpass=findViewById(R.id.userpass);
button=findViewById(R.id.button);
t_register.setOnClickListener(this);
t_login.setOnClickListener(this);
button.setOnClickListener(this);
dbAdapter = new DBAdapter(this);
dbAdapter.open();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.t_register:
Intent intent=new Intent(LoginActivity.this,RegisterActivity.class);
startActivity(intent);
break;
case R.id.t_login:
Intent intent2=new Intent(LoginActivity.this,ModifyPassActivity.class);
startActivity(intent2);
break;
case R.id.button:
String name,pass;
name=username.getText().toString();
pass=userpass.getText().toString();
People[] peoples = dbAdapter.queryOneData(name);
if ( peoples == null ) {
Toast toast=Toast.makeText(this,"数据库中没有此用户!",Toast.LENGTH_SHORT);
toast.show();
username.setText("");
userpass.setText("");
return;
}
else
{
if (peoples[0].Pass.equals(pass)) {
Toast toast=Toast.makeText(this,"登陆成功!",Toast.LENGTH_SHORT);
toast.show();
Intent intent1=new Intent(LoginActivity.this,NoteBookActivity.class);
intent1.putExtra("name",peoples[0].Name);
startActivity(intent1);
}
else {
Toast toast1=Toast.makeText(this,"密码输入错误!",Toast.LENGTH_SHORT);
toast1.show();
userpass.setText("");
}
}
}
}
}
(三)注册用户
package com.example.jishiben;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;
import android.widget.Toast;
public class RegisterActivity extends AppCompatActivity implements View.OnClickListener{
private EditText username,userpass1,userpass2;
private Spinner minzu;
private RadioButton nan,nv;
private Button zc,dl;
private DBAdapter dbAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
username=findViewById(R.id.edt_name);
userpass1=findViewById(R.id.edt_pss);
userpass2=findViewById(R.id.edt_pssConfirm);
minzu=findViewById(R.id.spinner);
nan=findViewById(R.id.rd_male);
nv=findViewById(R.id.rd_female);
zc=findViewById(R.id.btn_ok);
dl=findViewById(R.id.btn_login);
zc.setOnClickListener(this);
dl.setOnClickListener(this);
dbAdapter = new DBAdapter(this);
dbAdapter.open();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.btn_ok:
People people = new People() ;
String name,pass1,pass2,mz,sex;
name=username.getText().toString();
pass1=userpass1.getText().toString();
pass2=userpass2.getText().toString();
mz=minzu.getSelectedItem().toString();
if(nan.isChecked())sex="男";
else sex="女";
if (pass1.equals(pass2)) {
people.Name=name;
people.Pass=pass1;
people.Minzu=mz;
people.Sex=sex;
long colum = dbAdapter.insert(people);
if ( colum == -1 ) {
Toast toast=Toast.makeText(this, "添加过程错误!!", Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast=Toast.makeText(this, "成功添加数据!!", Toast.LENGTH_SHORT);
toast.show();
}
} else {
Toast toast=Toast.makeText(this, "两次密码输入不一致,请重新输入!!", Toast.LENGTH_SHORT);
toast.show();
userpass1.setText("");
userpass2.setText("");
}
break;
case R.id.btn_login:
Intent intent=new Intent(RegisterActivity.this,LoginActivity.class);
startActivity(intent);
}
}
}
(四)忘记密码
package com.example.jishiben;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class ModifyPassActivity extends AppCompatActivity implements View.OnClickListener{
private EditText name,oldpass,newpass,newpass1;
private Button query,modify;
private DBAdapter dbAdapter ;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_modify_pass);
name=findViewById(R.id.et_name);
oldpass=findViewById(R.id.et_oldpass);
newpass=findViewById(R.id.et_newpass);
newpass1=findViewById(R.id.et_newpass1);
query=findViewById(R.id.bt_query);
query.setOnClickListener(this);
modify=findViewById(R.id.bt_modify);
modify.setOnClickListener(this);
dbAdapter = new DBAdapter(this);
dbAdapter.open();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.bt_query:
String n=name.getText().toString();
String p;
People[] peoples =dbAdapter.queryOneData(n);
if (peoples == null) {
Toast toast= Toast.makeText(this,"用户名输入错误!",Toast.LENGTH_SHORT);
toast.show();
name.setText("");
return;
}
else
{
p=peoples[0].Pass;
oldpass.setText(p);
newpass1.setEnabled(true);
newpass.setEnabled(true);
}
break;
case R.id.bt_modify:
String p1,p2;
p1=newpass.getText().toString();
p2=newpass1.getText().toString();
if(!p1.equals(p2)) {
Toast toast= Toast.makeText(this,"两次密码不一致",Toast.LENGTH_SHORT);
toast.show();
newpass.setText("");
newpass1.setText("");
} else {
People people = new People();
people.Name =name.getText().toString();
long i=dbAdapter.updateOneData(p1,people);
if (i == -1) {
Toast toast= Toast.makeText(this,"更新错误",Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast= Toast.makeText(this,"更新成功",Toast.LENGTH_SHORT);
toast.show();
Intent intent=new Intent(ModifyPassActivity.this,LoginActivity.class);
startActivity(intent);
}
}
}
}
}
(五)用户信息
package com.example.jishiben;
public class People {
public int ID = -1;
public String Name;
public String Pass;
public String Sex;
public String Minzu;
@Override
public String toString(){
String result = "";
result += "ID:" + this.ID + ",";
result += "姓名:" + this.Name + ",";
result += "密码:" + this.Pass + ", ";
result += "性别:" + this.Sex + ",";
result += "民族:" + this.Minzu + ",";
return result;
}
}
values里面添加一个arrays.xml文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="minzu">
<item >汉族</item>
<item >回族</item>
<item >维吾尔族</item>
<item >哈萨克族</item>
<item >蒙古族</item>
<item >锡伯族</item>
<item >傣族</item>
</string-array>
</resources>
|