package com.example.test_one;标签:EditText,void,User,import,android,4.30,public From: https://www.cnblogs.com/kongxiangzeng/p/18246535
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import com.example.test_one.dao.UserDao;
import com.example.test_one.entity.User;
import java.sql.SQLException;
public class route extends AppCompatActivity {
private EditText routeEditText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_route);
// 初始化EditText
routeEditText = findViewById(R.id.b2);
}
public void 线路2(View view) {
// 获取EditText中的线路信息
String routeInput = routeEditText.getText().toString();
try {
// 将String类型转换为int类型
int routeInt = Integer.parseInt(routeInput);
// 创建User对象
User user = new User();
// 设置用户的地铁线路
user.setSubway_Line(routeInt);
Thread thread = new Thread() {
@Override
public void run() {
final String result = UserDao.route(user);
// 在主线程更新UI
runOnUiThread(new Runnable() {
@Override
public void run() {
TextView resultTextView = findViewById(R.id.b4);
resultTextView.setText(result);
}
});
}
};
thread.start();
} catch (NumberFormatException e) {
e.printStackTrace(); // 打印异常信息
}
}
}