冲刺阶段过半,开了一次小会,明确了第一阶段的冲刺目标,互相之间加油打气,队内相互鼓励,活跃了一下氛围
个人的登录功能的构建也日趋完善,期间也会有一些小问题,相互讨论,并在一些教程以及CSDN论坛的帖子中寻找解决问题的方法
Main2Activity
package com.example.demo2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class Main2Activity extends AppCompatActivity implements View.OnClickListener {
private String realCode;
private DBOpenHelper mDBOpenHelper;
private Button mBtRegisteractivityRegister;
private RelativeLayout mRlRegisteractivityTop;
private ImageView mIvRegisteractivityBack;
private LinearLayout mLlRegisteractivityBody;
private EditText mEtRegisteractivityUsername;
private EditText mEtRegisteractivityPassword1;
private EditText mEtRegisteractivityPassword2;
private EditText mEtRegisteractivityPhonecodes;
private ImageView mIvRegisteractivityShowcode;
private RelativeLayout mRlRegisteractivityBottom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
initView();
mDBOpenHelper = new DBOpenHelper(this);
}
private void initView(){
mBtRegisteractivityRegister = findViewById(R.id.bt_registeractivity_register);
mRlRegisteractivityTop = findViewById(R.id.rl_registeractivity_top);
mIvRegisteractivityBack = findViewById(R.id.iv_registeractivity_back);
mLlRegisteractivityBody = findViewById(R.id.ll_registeractivity_body);
mEtRegisteractivityUsername = findViewById(R.id.et_registeractivity_username);
mEtRegisteractivityPassword1 = findViewById(R.id.et_registeractivity_password1);
mEtRegisteractivityPassword2 = findViewById(R.id.et_registeractivity_password2);
mIvRegisteractivityBack.setOnClickListener(this);
mBtRegisteractivityRegister.setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.iv_registeractivity_back: //返回登录页面
Intent intent1 = new Intent(this, Main2Activity.class);
startActivity(intent1);
finish();
break;
case R.id.bt_registeractivity_register: //注册按钮
//获取用户输入的用户名、密码、验证码
String username = mEtRegisteractivityUsername.getText().toString().trim();
String password = mEtRegisteractivityPassword1.getText().toString().trim();
//注册验证
if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(password) ) {
//将用户名和密码加入到数据库中
mDBOpenHelper.add(username, password);
Intent intent2 = new Intent(this, MainActivity.class);
startActivity(intent2);
finish();
Toast.makeText(this, "验证通过,注册成功", Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(this, "未完善信息,注册失败", Toast.LENGTH_SHORT).show();
}
break;
}
}
}
User
package com.example.demo2;
public class User {
private String name; //用户名
private String password; //密码
public User(String name, String password) {
this.name = name;
this.password = password;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", password='" + password + '\'' +
'}';
}
}
DBOoenHelper
package com.example.demo2;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
public class DBOpenHelper extends SQLiteOpenHelper {
private SQLiteDatabase db;
public DBOpenHelper(Context context) {
super(context, "db_test", null, 1);
db = getReadableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE IF NOT EXISTS user(" +
"_id INTEGER PRIMARY KEY AUTOINCREMENT," +
"name TEXT," +
"password TEXT)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS user");
onCreate(db);
}
public void add(String name,String password){
db.execSQL("INSERT INTO user (name,password) VALUES(?,?)",new Object[]{name,password});
}
public void delete(String name,String password){
db.execSQL("DELETE FROM user WHERE name = AND password ="+name+password);
}
public void updata(String password){
db.execSQL("UPDATE user SET password = ?",new Object[]{password});
}
public ArrayList<User> getAllData(){
ArrayList<User> list = new ArrayList<User>();
Cursor cursor = db.query("user",null,null,null,null,null,"name DESC");
while(cursor.moveToNext()){
String name = cursor.getString(cursor.getColumnIndex("name"));
String password = cursor.getString(cursor.getColumnIndex("password"));
list.add(new User(name,password));
}
return list;
}
}