2024/3/18
所花时间:4小时
代码行:200行
博客量:1篇
了解到的知识点:进行安卓第一次作业的注册界面的编写
package com.example.enroll;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class enroll extends AppCompatActivity {
private EditText mEditText_user_ID;
private EditText mEditText_user_name;
private EditText mEditText_phone;
private EditText mEditText_user_class;
private Button mButton_enroll2;
/*
private String str_user_ID;
private String str_user_name;
private String str_phone;
private String str_user_class;
*/
private MySQLConnector mySQLConnector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enroll);
mEditText_user_ID=findViewById(R.id.Edit_user_ID);
mEditText_user_name=findViewById(R.id.Edit_user_name);
mEditText_phone=findViewById(R.id.Edit_phone);
mEditText_user_class=findViewById(R.id.Edit_user_class);
mButton_enroll2=findViewById(R.id.btn_enroll2);
mySQLConnector=new MySQLConnector();
mButton_enroll2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertData();
/*
str_user_ID=mEditText_user_ID.getText().toString();
str_user_name=mEditText_user_name.getText().toString();
str_phone=mEditText_phone.getText().toString();
str_user_class=mEditText_user_class.getText().toString();
Toast.makeText(enroll.this, "注册成功", Toast.LENGTH_LONG).show();*/
}
});
}
private void insertData(){
String str_user_ID=mEditText_user_ID.getText().toString();
String str_user_name=mEditText_user_name.getText().toString();
String str_phone=mEditText_phone.getText().toString();
String str_user_class=mEditText_user_class.getText().toString();
String user_password="123456";
try{
mySQLConnector.insertData(str_user_ID,str_user_name,str_phone,str_user_class,user_password);
Toast.makeText(enroll.this, "注册成功", Toast.LENGTH_LONG).show();
}catch(Exception e){
Toast.makeText(enroll.this, "注册成功", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class enroll extends AppCompatActivity {
private EditText mEditText_user_ID;
private EditText mEditText_user_name;
private EditText mEditText_phone;
private EditText mEditText_user_class;
private Button mButton_enroll2;
/*
private String str_user_ID;
private String str_user_name;
private String str_phone;
private String str_user_class;
*/
private MySQLConnector mySQLConnector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_enroll);
mEditText_user_ID=findViewById(R.id.Edit_user_ID);
mEditText_user_name=findViewById(R.id.Edit_user_name);
mEditText_phone=findViewById(R.id.Edit_phone);
mEditText_user_class=findViewById(R.id.Edit_user_class);
mButton_enroll2=findViewById(R.id.btn_enroll2);
mySQLConnector=new MySQLConnector();
mButton_enroll2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
insertData();
/*
str_user_ID=mEditText_user_ID.getText().toString();
str_user_name=mEditText_user_name.getText().toString();
str_phone=mEditText_phone.getText().toString();
str_user_class=mEditText_user_class.getText().toString();
Toast.makeText(enroll.this, "注册成功", Toast.LENGTH_LONG).show();*/
}
});
}
private void insertData(){
String str_user_ID=mEditText_user_ID.getText().toString();
String str_user_name=mEditText_user_name.getText().toString();
String str_phone=mEditText_phone.getText().toString();
String str_user_class=mEditText_user_class.getText().toString();
String user_password="123456";
try{
mySQLConnector.insertData(str_user_ID,str_user_name,str_phone,str_user_class,user_password);
Toast.makeText(enroll.this, "注册成功", Toast.LENGTH_LONG).show();
}catch(Exception e){
Toast.makeText(enroll.this, "注册成功", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
}