冲刺第一天

今天是任务分配和确立目标,还剩九天


主页面逻辑代码
`package com.example.yibaifen;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.yibaifen.Dao.StudentDao;
import com.example.yibaifen.Bean.Student;

public class Activity_register extends AppCompatActivity {

private EditText id;
private EditText youxiang;
private EditText phone;
private EditText zhiye;
private EditText password;
Button backLoginButton,signupbutton;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register);

    id = findViewById(R.id.StudentIdEdit);
    youxiang = findViewById(R.id.YouxiangEdit);
    phone = findViewById(R.id.PhoneEdit);
    zhiye = findViewById(R.id.ZhiyeEdit);
    password = findViewById(R.id.PasswordEdit);
    signupbutton = findViewById(R.id.SignUpButton);
    backLoginButton = findViewById(R.id.BackLoginButton);
    backLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // 返回到 MainActivity
            Intent intent = new Intent(Activity_register.this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    });
    signupbutton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String id1 = id.getText().toString();
            String youxiang1 = youxiang.getText().toString();
            String phone1 = phone.getText().toString();
            String zhiye1 = zhiye.getText().toString();
            String password1 = password.getText().toString();

            Student student = new Student();

            student.setId(id1);
            student.setPhone(phone1);
            student.setYouxiang(youxiang1);
            student.setPassword(password1);
            student.setZhiye(zhiye1);
            student.setHuolizhi("0");


            new Thread(){
                @Override
                public void run() {

                    int msg = 0;
                    StudentDao studentDao = new StudentDao();

                    Student s = studentDao.findStudent(student.getId());
                    if(s != null){
                        msg = 1;
                    }
                    else{
                        boolean flag = studentDao.register(student);
                        if(flag){
                            msg = 2;
                        }
                    }
                    hand.sendEmptyMessage(msg);
                }
            }.start();
        }
        @SuppressLint("HandlerLeak")
        final Handler hand = new Handler()
        {
            public void handleMessage(Message msg) {
                if(msg.what == 0) {
                    Toast.makeText(getApplicationContext(),"注册失败",Toast.LENGTH_LONG).show();
                } else if(msg.what == 1) {
                    Toast.makeText(getApplicationContext(),"该账号已经存在,请换一个账号",Toast.LENGTH_LONG).show();
                } else if(msg.what == 2) {
                    Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_LONG).show();
                    Intent intent = new Intent();
                    //将想要传递的数据用putExtra封装在intent中
                    intent.putExtra("a","注册");
                    setResult(RESULT_CANCELED,intent);
                    finish();
                }
            }

        };
    });
}

}
`

posted @ 2024-04-18 21:03  益百分  阅读(13)  评论(0)    收藏  举报