diff --git a/app/src/main/java/com/example/SearchCenter/SearchEntryActivity.java b/app/src/main/java/com/example/SearchCenter/SearchEntryActivity.java index 220e582..d8dd36b 100644 --- a/app/src/main/java/com/example/SearchCenter/SearchEntryActivity.java +++ b/app/src/main/java/com/example/SearchCenter/SearchEntryActivity.java @@ -2,7 +2,10 @@ package com.example.SearchCenter; import android.content.Intent; import android.os.Bundle; +import android.os.Message; import android.util.Log; +import android.view.View; +import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.LinearLayout; import android.widget.ListView; @@ -12,6 +15,8 @@ import androidx.appcompat.app.AppCompatActivity; import com.example.Util.ConditionCode; import com.example.Util.ReturnData; +import com.example.Util.cmkgWebServiceGet; +import com.example.Util.publicStringUtil; import com.example.cmknowledgegraph.R; import com.loopeer.cardstack.AllMoveDownAnimatorAdapter; import com.loopeer.cardstack.CardStackView; @@ -23,6 +28,7 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import java.util.Random; @@ -30,6 +36,8 @@ import java.util.Random; public class SearchEntryActivity extends AppCompatActivity implements CardStackView.ItemExpendListener,ConditionCode{ public static ArrayList content=new ArrayList();//存储数据内容 + public static String model_Text; + public static int[] index=new int[3];//在随机生成选定联想搜索产生的索引值 Integer[] color = { R.color.holo_blue_bright, R.color.holo_orange_light, @@ -174,17 +182,17 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV * 药——操作方法 联想搜索:nhm能治什么病 ,nhm的证候,nhm的功能 * 药——作用 联想搜索:nhm能治什么病,nhm的证候,nhm的功能 */ - TextView asscoiate_text=findViewById(R.id.asscoiate_text); - TextView[] textViews =new TextView[3]; - String[] texts=new String[3]; + TextView asscoiate_text=findViewById(R.id.asscoiate_text);//显示文本“你可能感兴趣” + String[] texts=new String[3];//存放listView中的显示的数据 if(response.getCode()==DiseaseToSymptom){ /** * 病——症状 nm能吃什么药 */ - TextView textView_1=findViewById(R.id.asscoiate_entry); - textView_1.setText(response.getMsg()+"应该吃什么药"); - texts[0]=(String)textView_1.getText(); + TextView textView=findViewById(R.id.asscoiate_entry); + textView.setText(response.getMsg()+"应该吃什么药"); + texts[0]=(String)textView.getText(); + model_Text=Model_Symptom; }else if(response.getCode()==DiseaseToMedicines){ /** * 病——药 nhm能指什么病,nhm能治什么病,nhm能治什么病 @@ -193,10 +201,11 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV Random r=new Random(); for(int i=0;i<3;i++) { TextView textView = findViewById(R.id.asscoiate_entry); - int index = r.nextInt(9) + 1; - textView.setText(content.get(index) + "能治什么病症"); + index[i] = r.nextInt(9) + 1; + textView.setText(content.get(index[i]) + "能治什么病症"); texts[i]=(String)textView.getText(); } + model_Text=Model_Medicines; }else if(response.getCode()==MedicineToOperation){ /** * 药——操作方法 @@ -205,24 +214,7 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV TextView textView_1=findViewById(R.id.asscoiate_entry); textView_1.setText(response.getMsg()+"能治什么病"); texts[0]=(String)textView_1.getText(); -// textView_1.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// new Thread(new Runnable() { -// @Override -// public void run() { -// ReturnData rd=cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname+response.getMsg()+"作用",publicStringUtil.questionSearchURL); -// Intent intent=new Intent(); -// Message m = new Message(); -// Bundle bundle = new Bundle(); -// bundle.putSerializable("msg", rd); -// intent.putExtras(bundle); -// intent.setClass(SearchEntryActivity.this,SearchEntryActivity.class); -// startActivity(intent); -// } -// }).start(); -// } -// }); + model_Text=Model_Function; }else { /** *药——作用,能治什么病 @@ -231,33 +223,37 @@ public class SearchEntryActivity extends AppCompatActivity implements CardStackV TextView textView=findViewById(R.id.asscoiate_entry); textView.setText(response.getMsg()+"的用法"); texts[0]=(String)textView.getText(); -// textView.setOnClickListener(new View.OnClickListener() { -// @Override -// public void onClick(View view) { -// new Thread(new Runnable() { -// @Override -// public void run() { -// ReturnData rd=cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname+response.getMsg()+"用法",publicStringUtil.questionSearchURL); -// Intent intent=new Intent(); -// Message m = new Message(); -// Bundle bundle = new Bundle(); -// bundle.putSerializable("msg", rd); -// intent.putExtras(bundle); -// intent.setClass(SearchEntryActivity.this,SearchEntryActivity.class); -// startActivity(intent); -// } -// }).start(); -// } -// }); - + model_Text=Model_Operation; } - - ArrayAdapter view_adapter = new ArrayAdapter(SearchEntryActivity.this,android.R.layout.simple_list_item_1, texts); ListView listView=findViewById(R.id.listview_group); - listView.setAdapter(view_adapter); - + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int position, long l) { + new Thread(new Runnable() { + @Override + public void run() { + ReturnData rd=null; + if(response.getCode()==DiseaseToMedicines) { + rd = cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname + content.get(index[position]) + model_Text, publicStringUtil.questionSearchURL); + } + else{ + rd= cmkgWebServiceGet.executeHttpGet(publicStringUtil.questionArgsname+response.getMsg()+model_Text, publicStringUtil.questionSearchURL); + } + Message m = new Message(); + Bundle bundle = new Bundle(); + bundle.putSerializable("msg", rd); + Intent intent = new Intent(); + intent.setClass(SearchEntryActivity.this, SearchEntryActivity.class); + intent.putExtras(bundle); + startActivity(intent); + } + }).start(); + } + }); + listView.setAdapter(view_adapter); + adapter.updateData(Arrays.asList(new_color),lists); } } diff --git a/app/src/main/java/com/example/Util/ConditionCode.java b/app/src/main/java/com/example/Util/ConditionCode.java index aca2ad1..2c15787 100644 --- a/app/src/main/java/com/example/Util/ConditionCode.java +++ b/app/src/main/java/com/example/Util/ConditionCode.java @@ -12,5 +12,15 @@ public interface ConditionCode { public final int DiseaseToMedicines=200; public final int MedicineToOperation=300; public final int MedicineToSymptom=400; + /*** + *Model_Symptom 匹配模板 病——症状 + * Model_Medicines 匹配模板 病——治疗方法 + * Model_Operation 匹配模板 药——用法 + * Model_Function 匹配模板 药——作用 + */ + public final String Model_Symptom="的症状"; + public final String Model_Medicines="治疗方法"; + public final String Model_Operation="用法"; + public final String Model_Function="作用"; } diff --git a/app/src/main/res/layout/activity_search_entry.xml b/app/src/main/res/layout/activity_search_entry.xml index 6666373..e9dcfca 100644 --- a/app/src/main/res/layout/activity_search_entry.xml +++ b/app/src/main/res/layout/activity_search_entry.xml @@ -16,8 +16,9 @@