完成注册工作 难死了tmd标签:String,void,id,3.22,rg,import,public From: https://www.cnblogs.com/wcy1111/p/18253767
package com.example.my2mysql.activiy;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import com.example.my2mysql.R;
import com.example.my2mysql.tool.okhttp3manager;
public class registerActivity extends AppCompatActivity {
private EditText rg_id, rg_name, rg_password, rg_sclass, rg_phone;
private Button registerButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.register_activity);
init();
}
public void init() {
rg_id = findViewById(R.id.rg_id);
rg_name = findViewById(R.id.rg_name);
rg_password = findViewById(R.id.rg_password);
rg_sclass = findViewById(R.id.rg_sclass);
rg_phone = findViewById(R.id.rg_phone);
registerButton = findViewById(R.id.bt_register);
registerButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String id = rg_id.getText().toString();
String name = rg_name.getText().toString();
String password = rg_password.getText().toString();
String sclass = rg_sclass.getText().toString();
String phone = rg_phone.getText().toString();
new Thread() {
@Override
public void run() {
okhttp3manager.register(id, name, password, sclass, phone, new okhttp3manager.RegisterCallback() {
@Override
public void RegisterSuccess(final String successMessage) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(registerActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
}
});
if (successMessage.equals("注册成功")) {
Intent intent = new Intent(registerActivity.this, MainActivity2.class);
startActivity(intent);
finish();
}
}
@Override
public void RegisterFailure(final String errorMessage) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(registerActivity.this, errorMessage, Toast.LENGTH_SHORT).show();
}
});
}
});
}
}.start();
}
});
}
}