2024/6/1

所学时间:2小时

代码行数:100

博客园数:1篇

所学知识:

package com.example.kanglaojian;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import java.lang.ref.PhantomReference;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class information extends AppCompatActivity {
private String selectedItem,selectedItem1;
private Button breturn,chat;
private String name="";
private MySQLConnector mySQLConnector;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_information);
breturn=findViewById(R.id.breturn);
chat=findViewById(R.id.chat);
selectedItem = getIntent().getStringExtra("selectedItem");
@SuppressLint({"MissingInflatedId", "LocalSuppress"})
TextView textView = findViewById(R.id.textView);
textView.setText(selectedItem);
for (int i = 0; i < selectedItem.length(); i++) {
if(selectedItem.charAt(i)=='('){
break;
}
name+=selectedItem.charAt(i);
}
new Thread(new Runnable() {
@Override
public void run() {
try{
Connection connection=mySQLConnector.getConn();
String sql="select introduce from doctor where name='"+name+"'";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
resultSet.next();
selectedItem1=resultSet.getString("introduce");
TextView textView1= findViewById(R.id.textView1);
textView1.setText(selectedItem1);
}catch (Exception e) {

}
}
}).start();
breturn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(information.this, consultation.class);
startActivity(intent);
}
});
chat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(information.this, Chat.class);
intent.putExtra("name", name);
startActivity(intent);
}
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".information"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_centerInParent="true" />


</LinearLayout>
<LinearLayout
android:layout_width="300dp"
android:layout_height="600dp"
android:layout_gravity="center"
android:gravity="center">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:layout_centerInParent="true" />
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="match_parent"
android:layout_height="70dp"
android:gravity="center">
<Button
android:id="@+id/breturn"
android:layout_width="130dp"
android:layout_height="match_parent"
android:text="返回"
android:textSize="20dp"
android:backgroundTint="@color/blue">

</Button>
<Space
android:layout_width="50dp"
android:layout_height="wrap_content">
</Space>
<Button
android:id="@+id/chat"
android:layout_width="130dp"
android:layout_height="match_parent"
android:text="聊天"
android:textSize="20dp"
android:backgroundTint="@color/blue">

</Button>
</LinearLayout>
</LinearLayout>
posted @ 2024-06-01 20:14  为20岁努力  阅读(2)  评论(0编辑  收藏  举报