2024/5/30
所学时间: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"
android:orientation="vertical"
tools:context=".medication_search">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/query_medication"
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/medication_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/blue"
android:text="搜索">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="horizontal">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="编号"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="名称"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="俗名"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="价格"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="是否纳入医保"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="操作"
android:textSize="20dp" />
</TableRow>
<TableRow>
<ListView
android:id="@+id/InaccountInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<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"
android:orientation="vertical"
tools:context=".medication_search">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/query_medication"
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/medication_query"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:backgroundTint="@color/blue"
android:text="搜索">
</Button>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:orientation="horizontal">
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="编号"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="名称"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="俗名"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="价格"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="是否纳入医保"
android:textSize="20dp" />
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="操作"
android:textSize="20dp" />
</TableRow>
<TableRow>
<ListView
android:id="@+id/InaccountInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
<ListView
android:id="@+id/InaccountInfo5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
</ListView>
</TableRow>
</TableLayout>
</LinearLayout>
</LinearLayout>
package com.example.kanglaojian;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.ConditionVariable;
import android.text.Html;
import android.text.Spanned;
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.TextView;
import org.checkerframework.checker.units.qual.A;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.annotation.Nullable;
import io.grpc.internal.JsonUtil;
public class medication_search extends Fragment {
private Button medication_query;
private EditText query_medication;
private String str_query_medication;
ArrayList<String> ListNumber = new ArrayList<>();
ArrayList<String> tListNumber = new ArrayList<>();
ArrayList<String> ListName=new ArrayList<>();
ArrayList<String> tListName=new ArrayList<>();
ArrayList<String> ListPopularname=new ArrayList<>();
ArrayList<String> tListPopularname=new ArrayList<>();
ArrayList<String> ListPrice=new ArrayList<>();
ArrayList<String> tListPrice=new ArrayList<>();
ArrayList<String> ListHealthinsurance=new ArrayList<>();
ArrayList<String> tListHealthinsurance=new ArrayList<>();
private ListView InaccountInfo,InaccountInfo1,InaccountInfo2,InaccountInfo3,InaccountInfo4,InaccountInfo5;
private MySQLConnector mySQLConnector;
public medication_search(){
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
return inflater.inflate(R.layout.activity_medication_search, 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 number,name,popularname,price,healthinsurance,effect from drugs ";
PreparedStatement ps=connection.prepareStatement(sql1);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String tnumber=resultSet.getString("number");
tListNumber.add(tnumber);
String tname=resultSet.getString("name");
tListName.add(tname);
String tpopularname=resultSet.getString("popularname");
tListPopularname.add(tpopularname);
String tprice=resultSet.getString("price");
tListPrice.add(tprice);
String thealthinsurance=resultSet.getString("healthinsurance");
tListHealthinsurance.add(thealthinsurance);
}
}catch (Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String[] tnumber = new String[tListNumber.size()];
String[] tname=new String[tListName.size()];
String[] tpopularname=new String[tListPopularname.size()];
String[] tprice=new String[tListPrice.size()];
String[] thealthinsurance=new String[tListHealthinsurance.size()];
String[] toperation=new String[tListNumber.size()];
for (int i = 0; i < tListNumber.size(); i++) {
tnumber[i] = tListNumber.get(i);
tname[i]=tListName.get(i);
tpopularname[i]=tListPopularname.get(i);
tprice[i]=tListPrice.get(i);
thealthinsurance[i]=tListHealthinsurance.get(i);
toperation[i]="查看药物效果";
}
ArrayAdapter<String> tadapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tnumber);
InaccountInfo.setAdapter(tadapter);
ArrayAdapter<String> tadapter1 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tname);
InaccountInfo1.setAdapter(tadapter1);
ArrayAdapter<String> tadapter2 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tpopularname);
InaccountInfo2.setAdapter(tadapter2);
ArrayAdapter<String> tadapter3 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tprice);
InaccountInfo3.setAdapter(tadapter3);
ArrayAdapter<String> tadapter4 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, thealthinsurance);
InaccountInfo4.setAdapter(tadapter4);
ArrayAdapter<String> tadapter5 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, toperation);
InaccountInfo5.setAdapter(tadapter5);
InaccountInfo5.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
String sql2="select effect from drugs where popularname ='心得安'";
PreparedStatement ps=connection.prepareStatement(sql2);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("effect");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();
}
});
}
});
}
}).start();
query_medication=view.findViewById(R.id.query_medication);
medication_query=view.findViewById(R.id.medication_query);
InaccountInfo=(ListView)getView().findViewById(R.id.InaccountInfo);
InaccountInfo1=(ListView)getView().findViewById(R.id.InaccountInfo1);
InaccountInfo2=(ListView)getView().findViewById(R.id.InaccountInfo2);
InaccountInfo3=(ListView)getView().findViewById(R.id.InaccountInfo3);
InaccountInfo4=(ListView)getView().findViewById(R.id.InaccountInfo4);
InaccountInfo5=(ListView)getView().findViewById(R.id.InaccountInfo5);
medication_query.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try{
System.out.println("11111111111111111111111111111111111111");
ListNumber.clear();ListName.clear();ListPopularname.clear();ListPrice.clear();ListHealthinsurance.clear();
Connection connection=mySQLConnector.getConn();
str_query_medication=query_medication.getText().toString();
String sql="select number,name,popularname,price,healthinsurance,effect from drugs where name like '%"+str_query_medication+"%' or popularname like '%"+str_query_medication+"%'";
Log.e("111111111111111111111111111","select number,name,popularname,price,healthinsurance,effect from drugs where name like '%"+str_query_medication+"%' or popularname like '%"+str_query_medication+"%'");
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String snumber=resultSet.getString("number");
ListNumber.add(snumber);
String sname=resultSet.getString("name");
ListName.add(sname);
String spopularname=resultSet.getString("popularname");
ListPopularname.add(spopularname);
String sprice=resultSet.getString("price");
ListPrice.add(sprice);
String shealthinsurance=resultSet.getString("healthinsurance");
ListHealthinsurance.add(shealthinsurance);
}
}catch (Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e("222222222222222222222222","22222222222222222222222222222");
String[] number = new String[ListNumber.size()];
Log.e("222222222222222222222222","23333333333333333333");
String[] name=new String[ListName.size()];
String[] popularname=new String[ListPopularname.size()];
String[] price=new String[ListPrice.size()];
String[] healthinsurance=new String[ListHealthinsurance.size()];
String[] operation=new String[ListNumber.size()];
for (int i = 0; i < ListNumber.size(); i++) {
number[i] = ListNumber.get(i);
name[i]=ListName.get(i);
popularname[i]=ListPopularname.get(i);
price[i]=ListPrice.get(i);
healthinsurance[i]=ListHealthinsurance.get(i);
operation[i]="查看药物效果";
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, number);
InaccountInfo.setAdapter(adapter);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, name);
InaccountInfo1.setAdapter(adapter1);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, popularname);
InaccountInfo2.setAdapter(adapter2);
ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, price);
InaccountInfo3.setAdapter(adapter3);
ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, healthinsurance);
InaccountInfo4.setAdapter(adapter4);
ArrayAdapter<String> adapter5 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, operation);
InaccountInfo5.setAdapter(adapter5);
InaccountInfo5.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
String sql="select effect from drugs where name like '%"+str_query_medication+"%' or popularname like '%"+str_query_medication+"%' ";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("effect");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();
}
});
}
});
}
}).start();
}
});
}
private void showBlankDialog(String temp){
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("药物效果详情")
.setMessage(temp)
.setPositiveButton("关闭", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
}
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.ConditionVariable;
import android.text.Html;
import android.text.Spanned;
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.TextView;
import org.checkerframework.checker.units.qual.A;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import javax.annotation.Nullable;
import io.grpc.internal.JsonUtil;
public class medication_search extends Fragment {
private Button medication_query;
private EditText query_medication;
private String str_query_medication;
ArrayList<String> ListNumber = new ArrayList<>();
ArrayList<String> tListNumber = new ArrayList<>();
ArrayList<String> ListName=new ArrayList<>();
ArrayList<String> tListName=new ArrayList<>();
ArrayList<String> ListPopularname=new ArrayList<>();
ArrayList<String> tListPopularname=new ArrayList<>();
ArrayList<String> ListPrice=new ArrayList<>();
ArrayList<String> tListPrice=new ArrayList<>();
ArrayList<String> ListHealthinsurance=new ArrayList<>();
ArrayList<String> tListHealthinsurance=new ArrayList<>();
private ListView InaccountInfo,InaccountInfo1,InaccountInfo2,InaccountInfo3,InaccountInfo4,InaccountInfo5;
private MySQLConnector mySQLConnector;
public medication_search(){
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
return inflater.inflate(R.layout.activity_medication_search, 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 number,name,popularname,price,healthinsurance,effect from drugs ";
PreparedStatement ps=connection.prepareStatement(sql1);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String tnumber=resultSet.getString("number");
tListNumber.add(tnumber);
String tname=resultSet.getString("name");
tListName.add(tname);
String tpopularname=resultSet.getString("popularname");
tListPopularname.add(tpopularname);
String tprice=resultSet.getString("price");
tListPrice.add(tprice);
String thealthinsurance=resultSet.getString("healthinsurance");
tListHealthinsurance.add(thealthinsurance);
}
}catch (Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
String[] tnumber = new String[tListNumber.size()];
String[] tname=new String[tListName.size()];
String[] tpopularname=new String[tListPopularname.size()];
String[] tprice=new String[tListPrice.size()];
String[] thealthinsurance=new String[tListHealthinsurance.size()];
String[] toperation=new String[tListNumber.size()];
for (int i = 0; i < tListNumber.size(); i++) {
tnumber[i] = tListNumber.get(i);
tname[i]=tListName.get(i);
tpopularname[i]=tListPopularname.get(i);
tprice[i]=tListPrice.get(i);
thealthinsurance[i]=tListHealthinsurance.get(i);
toperation[i]="查看药物效果";
}
ArrayAdapter<String> tadapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tnumber);
InaccountInfo.setAdapter(tadapter);
ArrayAdapter<String> tadapter1 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tname);
InaccountInfo1.setAdapter(tadapter1);
ArrayAdapter<String> tadapter2 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tpopularname);
InaccountInfo2.setAdapter(tadapter2);
ArrayAdapter<String> tadapter3 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, tprice);
InaccountInfo3.setAdapter(tadapter3);
ArrayAdapter<String> tadapter4 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, thealthinsurance);
InaccountInfo4.setAdapter(tadapter4);
ArrayAdapter<String> tadapter5 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, toperation);
InaccountInfo5.setAdapter(tadapter5);
InaccountInfo5.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
String sql2="select effect from drugs where popularname ='心得安'";
PreparedStatement ps=connection.prepareStatement(sql2);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("effect");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();
}
});
}
});
}
}).start();
query_medication=view.findViewById(R.id.query_medication);
medication_query=view.findViewById(R.id.medication_query);
InaccountInfo=(ListView)getView().findViewById(R.id.InaccountInfo);
InaccountInfo1=(ListView)getView().findViewById(R.id.InaccountInfo1);
InaccountInfo2=(ListView)getView().findViewById(R.id.InaccountInfo2);
InaccountInfo3=(ListView)getView().findViewById(R.id.InaccountInfo3);
InaccountInfo4=(ListView)getView().findViewById(R.id.InaccountInfo4);
InaccountInfo5=(ListView)getView().findViewById(R.id.InaccountInfo5);
medication_query.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new Thread(new Runnable() {
@Override
public void run() {
try{
System.out.println("11111111111111111111111111111111111111");
ListNumber.clear();ListName.clear();ListPopularname.clear();ListPrice.clear();ListHealthinsurance.clear();
Connection connection=mySQLConnector.getConn();
str_query_medication=query_medication.getText().toString();
String sql="select number,name,popularname,price,healthinsurance,effect from drugs where name like '%"+str_query_medication+"%' or popularname like '%"+str_query_medication+"%'";
Log.e("111111111111111111111111111","select number,name,popularname,price,healthinsurance,effect from drugs where name like '%"+str_query_medication+"%' or popularname like '%"+str_query_medication+"%'");
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet resultSet=ps.executeQuery();
while(resultSet.next()){
String snumber=resultSet.getString("number");
ListNumber.add(snumber);
String sname=resultSet.getString("name");
ListName.add(sname);
String spopularname=resultSet.getString("popularname");
ListPopularname.add(spopularname);
String sprice=resultSet.getString("price");
ListPrice.add(sprice);
String shealthinsurance=resultSet.getString("healthinsurance");
ListHealthinsurance.add(shealthinsurance);
}
}catch (Exception e){
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Log.e("222222222222222222222222","22222222222222222222222222222");
String[] number = new String[ListNumber.size()];
Log.e("222222222222222222222222","23333333333333333333");
String[] name=new String[ListName.size()];
String[] popularname=new String[ListPopularname.size()];
String[] price=new String[ListPrice.size()];
String[] healthinsurance=new String[ListHealthinsurance.size()];
String[] operation=new String[ListNumber.size()];
for (int i = 0; i < ListNumber.size(); i++) {
number[i] = ListNumber.get(i);
name[i]=ListName.get(i);
popularname[i]=ListPopularname.get(i);
price[i]=ListPrice.get(i);
healthinsurance[i]=ListHealthinsurance.get(i);
operation[i]="查看药物效果";
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, number);
InaccountInfo.setAdapter(adapter);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, name);
InaccountInfo1.setAdapter(adapter1);
ArrayAdapter<String> adapter2 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, popularname);
InaccountInfo2.setAdapter(adapter2);
ArrayAdapter<String> adapter3 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, price);
InaccountInfo3.setAdapter(adapter3);
ArrayAdapter<String> adapter4 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, healthinsurance);
InaccountInfo4.setAdapter(adapter4);
ArrayAdapter<String> adapter5 = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, operation);
InaccountInfo5.setAdapter(adapter5);
InaccountInfo5.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String result=((TextView)view).getText().toString();
final String[] tt={""};
new Thread(new Runnable() {
@Override
public void run() {
try {
Connection connection=mySQLConnector.getConn();
String sql="select effect from drugs where name like '%"+str_query_medication+"%' or popularname like '%"+str_query_medication+"%' ";
PreparedStatement ps=connection.prepareStatement(sql);
ResultSet res=ps.executeQuery();
while(res.next()){
tt[0]=res.getString("effect");
}
} catch (SQLException e) {
throw new RuntimeException(e);
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
Spanned spannedText = Html.fromHtml(tt[0]);
String plainText = spannedText.toString();
showBlankDialog(plainText);
}
});
}
}).start();
}
});
}
});
}
}).start();
}
});
}
private void showBlankDialog(String temp){
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
builder.setTitle("药物效果详情")
.setMessage(temp)
.setPositiveButton("关闭", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).show();
}
}