学习时间:2h
代码量:100
package com.example.text_five;标签:2024.3,21,EditText,软件工程,user,new,import,android,String From: https://www.cnblogs.com/luoqingci/p/18093370
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.example.text_five.dao.UserDao;
import com.example.text_five.entity.User;
/**
* function:注册页面
*/
public class register extends AppCompatActivity {
private static final String TAG = "mysql-party-MainActivity";
EditText userAccount = null;
EditText userName = null;
EditText userPhone = null;
EditText userClass = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
userAccount = findViewById(R.id.e2);
userName = findViewById(R.id.e3);
userPhone = findViewById(R.id.e4);
userClass= findViewById(R.id.e5);
}
public void sure(View view) {
String userAccount1 = userAccount.getText().toString();
String userName1= userName.getText().toString();
String userPhone1= userPhone.getText().toString();
String userClass1= userClass.getText().toString();
User user = new User();
user.setUserAccount(userAccount1);
user.setUserName(userName1);
user.setUserPhone(userPhone1);
user.setUserClass(userClass1);
new Thread(){
@Override
public void run() {
UserDao userDao = new UserDao();
boolean flag = userDao.register(user);
if(flag){
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(register.this, "注册成功", Toast.LENGTH_LONG).show();
startActivity(new Intent(register.this, MainActivity.class));
}
});
}
}
}.start();
}
}