2024/5/27
所学时间:2小时
代码行数:500
博客园数:1篇
所学知识:
<?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=".consultation"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="问医生"
android:textSize="20sp">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/query_doctor"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@drawable/round_edittext_bg"
android:hint="请输入要查找的医生">
</EditText>
<Button
android:id="@+id/doctor_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索"
android:backgroundTint="@color/blue"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ListView
android:id="@+id/DInaccountInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<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=".consultation"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="问医生"
android:textSize="20sp">
</TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/query_doctor"
android:layout_width="300dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@drawable/round_edittext_bg"
android:hint="请输入要查找的医生">
</EditText>
<Button
android:id="@+id/doctor_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="搜索"
android:backgroundTint="@color/blue"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ListView
android:id="@+id/DInaccountInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
package com.example.kanglaojian;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.annotation.Nullable;
import io.grpc.internal.JsonUtil;
public class consultation extends Fragment {
private Button doctor_query;
private EditText query_doctor;
private String str_query_doctor;
ArrayList<String> ListDoctor=new ArrayList<>();
ArrayList<String> temp=new ArrayList<>();
ArrayAdapter<String> adapter;
ArrayAdapter<String> t_adapter;
private ListView InaccountInfo;
private String[] doctor,t_doctor;
private MySQLConnector mySQLConnector;
public consultation(){
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
return inflater.inflate(R.layout.activity_consultation, container, false);
}
public void onViewCreated(@NonNull View view, @NonNull Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
String sql1="select name,hospital,department from doctor";
PreparedStatement ps=connection.prepareStatement(sql1);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String sdoctor=resultSet.getString("name");
String shospital=resultSet.getString("hospital");
String sdepartment=resultSet.getString("department");
temp.add(sdoctor+"("+shospital+" "+sdepartment+")");
}
}catch (Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
t_doctor= new String[temp.size()];
for (int i = 0; i <temp.size() ; i++) {
t_doctor[i]=temp.get(i);
}
t_adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, t_doctor);
InaccountInfo.setAdapter(t_adapter);
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = (String) parent.getItemAtPosition(position);
// 在这里实现页面跳转逻辑,可以使用 Intent
Intent intent = new Intent(getActivity(), information.class);
// 可选:传递额外的数据到下一个页面
intent.putExtra("selectedItem", selectedItem);
startActivity(intent);
}
});
}
});
}
}).start();
query_doctor=view.findViewById(R.id.query_doctor);
doctor_query=view.findViewById(R.id.doctor_query);
InaccountInfo=(ListView)getView().findViewById(R.id.DInaccountInfo);
doctor_query.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
str_query_doctor=query_doctor.getText().toString();
String sql="select name,hospital,department from doctor where hospital like '%"+str_query_doctor+"%'or name like '%"+str_query_doctor+"%'or department like '%"+str_query_doctor+"%'";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String sdoctor=resultSet.getString("name");
String shospital=resultSet.getString("hospital");
String sdepartment=resultSet.getString("department");
ListDoctor.add(sdoctor+"("+shospital+" "+sdepartment+")");
}
}catch(Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
doctor=new String[ListDoctor.size()];
for (int i = 0; i <ListDoctor.size() ; i++) {
doctor[i]=ListDoctor.get(i);
}
adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, doctor);
InaccountInfo.setAdapter(adapter);
if(InaccountInfo == null){
Log.e("111111111111111111111111","1111111111111111111111111");
}
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = (String) parent.getItemAtPosition(position);
// 在这里实现页面跳转逻辑,可以使用 Intent
Intent intent = new Intent(getActivity(), information.class);
// 可选:传递额外的数据到下一个页面
intent.putExtra("selectedItem", selectedItem);
startActivity(intent);
}
});
}
});
}
}).start();
}
});
}
}
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.annotation.Nullable;
import io.grpc.internal.JsonUtil;
public class consultation extends Fragment {
private Button doctor_query;
private EditText query_doctor;
private String str_query_doctor;
ArrayList<String> ListDoctor=new ArrayList<>();
ArrayList<String> temp=new ArrayList<>();
ArrayAdapter<String> adapter;
ArrayAdapter<String> t_adapter;
private ListView InaccountInfo;
private String[] doctor,t_doctor;
private MySQLConnector mySQLConnector;
public consultation(){
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
return inflater.inflate(R.layout.activity_consultation, container, false);
}
public void onViewCreated(@NonNull View view, @NonNull Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
String sql1="select name,hospital,department from doctor";
PreparedStatement ps=connection.prepareStatement(sql1);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String sdoctor=resultSet.getString("name");
String shospital=resultSet.getString("hospital");
String sdepartment=resultSet.getString("department");
temp.add(sdoctor+"("+shospital+" "+sdepartment+")");
}
}catch (Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
t_doctor= new String[temp.size()];
for (int i = 0; i <temp.size() ; i++) {
t_doctor[i]=temp.get(i);
}
t_adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, t_doctor);
InaccountInfo.setAdapter(t_adapter);
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = (String) parent.getItemAtPosition(position);
// 在这里实现页面跳转逻辑,可以使用 Intent
Intent intent = new Intent(getActivity(), information.class);
// 可选:传递额外的数据到下一个页面
intent.putExtra("selectedItem", selectedItem);
startActivity(intent);
}
});
}
});
}
}).start();
query_doctor=view.findViewById(R.id.query_doctor);
doctor_query=view.findViewById(R.id.doctor_query);
InaccountInfo=(ListView)getView().findViewById(R.id.DInaccountInfo);
doctor_query.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
str_query_doctor=query_doctor.getText().toString();
String sql="select name,hospital,department from doctor where hospital like '%"+str_query_doctor+"%'or name like '%"+str_query_doctor+"%'or department like '%"+str_query_doctor+"%'";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String sdoctor=resultSet.getString("name");
String shospital=resultSet.getString("hospital");
String sdepartment=resultSet.getString("department");
ListDoctor.add(sdoctor+"("+shospital+" "+sdepartment+")");
}
}catch(Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
doctor=new String[ListDoctor.size()];
for (int i = 0; i <ListDoctor.size() ; i++) {
doctor[i]=ListDoctor.get(i);
}
adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, doctor);
InaccountInfo.setAdapter(adapter);
if(InaccountInfo == null){
Log.e("111111111111111111111111","1111111111111111111111111");
}
InaccountInfo.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedItem = (String) parent.getItemAtPosition(position);
// 在这里实现页面跳转逻辑,可以使用 Intent
Intent intent = new Intent(getActivity(), information.class);
// 可选:传递额外的数据到下一个页面
intent.putExtra("selectedItem", selectedItem);
startActivity(intent);
}
});
}
});
}
}).start();
}
});
}
}