package com.example.test_one;标签:Toast,void,new,import,android,public,4.26 From: https://www.cnblogs.com/kongxiangzeng/p/18246533
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;
public class MainActivity extends AppCompatActivity {
EditText account;
EditText password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
account = findViewById(R.id.account);
password = findViewById(R.id.password);
}
// 跳转登录
public void login(View view) {
String account1 = account.getText().toString();
String password1 = password.getText().toString();
Thread thread = new Thread() {
public void run() {
if (UserDao.login(account1, password1)) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
}
});
startActivity(new Intent(MainActivity.this, Function_page.class));
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(MainActivity.this, "登录失败", Toast.LENGTH_SHORT).show();
}
});
}
}
};
thread.start();
}
// 跳转注册
public void reg(View view) {
startActivity(new Intent(this, register.class));
}
}