package com.example.test_one;标签:Toast,register,4.29,import,new,android,public From: https://www.cnblogs.com/kongxiangzeng/p/18246534
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.example.test_one.dao.UserDao;
import com.example.test_one.entity.User;
public class register extends AppCompatActivity {
EditText account;
EditText password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
account = findViewById(R.id.e2);
password = findViewById(R.id.e3);
}
public void sure(View view) {
String account1 = account.getText().toString();
String password1 = password.getText().toString();
User user = new User();
user.setAccount(account1);
user.setPassword(password1);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
if (UserDao.register(user)) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(register.this, "注册成功", Toast.LENGTH_SHORT).show();
}
});
Intent intent = new Intent(register.this, MainActivity.class);
startActivity(intent);
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(register.this, "注册失败", Toast.LENGTH_SHORT).show();
}
});
}
}
});
thread.start();
}
}