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; import android.widget.TextView; 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; import com.loopeer.cardstack.UpDownAnimatorAdapter; import com.loopeer.cardstack.UpDownStackAnimatorAdapter; import org.json.JSONArray; 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; 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, R.color.holo_purple, R.color.holo_red_light, R.color.holo_blue_dark, R.color.holo_orange_dark, R.color.holo_blue_dark, R.color.holo_red_dark, R.color.holo_orange_light, R.color.holo_red_dark }; private CardStackView mStackView; private LinearLayout mActionButtonContainer; private CMKGStackAdapter cmkgStackAdapter; Integer[] new_color; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search_entry); Intent intent = getIntent(); Bundle bundle = intent.getExtras(); init(bundle); } public void onItemExpend(boolean expend) { } void init(Bundle bundle) { List> lists=new LinkedList<>(); //获取response后,将这个json数据解析 ReturnData response = (ReturnData) bundle.getSerializable("msg"); Log.i("response+++++",response+"返回值"); try { int code = response.getCode(); Log.i("code:",""+code); String message = response.getMsg(); Log.i("msg:",""+message); if(code == DiseaseToSymptom){ /** * //返回的是病症 * 标题就是病的名字,内容就是症状。lists就是病名,list就是病症 */ List list = new LinkedList<>(); list.add(new ContentData((String)response.getData())); lists.add(list); new_color=new Integer[1]; }else if(code==DiseaseToMedicines){ /** * //返回的是结解决的多种药品方法 * 标题就是药品的名字,内容就是用法,暂时不做用法(用法先用数字代替) */ Log.i("hah",""+(String)response.getData()); JSONArray jsonArray = new JSONArray((String)response.getData()); for(int i=0;i list=new LinkedList<>(); list.add(new ContentData("我是您的用法哦~请您看看我嘞\n我无比的期待您的光临嘞\n我们没有连数据呢,马上就有嘞!")); content.add((String) jsonArray.get(i)); lists.add(list); } new_color=new Integer[jsonArray.length()]; }else if(code==MedicineToOperation) { /** * //返回的是药的用法 * //标题就是药品的名字,内容是用法 */ List list = new LinkedList<>(); list.add(new ContentData((String)response.getData())); lists.add(list); new_color=new Integer[1]; }else{ /** * //返回的是药的主治症状和对应的 * 标题是药的名字和“可以治疗的疾病”,内容是症状,和十种药物 */ List list = new LinkedList<>(); JSONObject jo=(JSONObject)response.getData(); String medicine_symptom=jo.getString("symptom"); list.add(new ContentData(medicine_symptom)); lists.add(list); String disease_names=new String(jo.getString("name")); JSONArray ja=new JSONArray(disease_names); for(int i=0;i list_1=new LinkedList<>(); list_1.add(new ContentData(content.get(i))); lists.add(list); } new_color=new Integer[1]; } for(int i=0;i view_adapter = new ArrayAdapter(SearchEntryActivity.this,R.layout.list_view, texts); ListView listView=findViewById(R.id.listview_group); 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); } }