Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. {
  2. "interactions":
  3. [
  4. {
  5. "MDT1": "ACIDE ACETOHYDROXAMIQUE",
  6. "MDT2": "FER",
  7. "CI": "",
  8. "AD": "",
  9. "PE": "",
  10. "PC": "A prendre en compte Diminution de l'absorption digestive de ces deux medicaments par chelation du fer..."
  11. },
  12. {
  13. "MDT1": "ACETAZOLAMIDE",
  14. "MDT2": "ACIDE ACETYLSALICYLIQUE",
  15. "CI": "",
  16. "AD": "Association DECONSEILLEE Majoration des effets indesirables.....",
  17. "PE": "",
  18. "PC": ""
  19. },
  20. {
  21. "MDT1": "ACETAZOLAMIDE",
  22. "MDT2": "CARBAMAZEPINE",
  23. "CI": "",
  24. "AD": "",
  25. "PE": "Precaution d'emploi Surveillance clinique........",
  26. "PC": ""
  27. },
  28. {
  29. "MDT1": "CARBAMAZEPINE",
  30. "MDT2": "OLANZAPINE",
  31. "CI": "",
  32. "AD": "",
  33. "PE": "Precaution d'emploi Surveillance clinique, et si besoin, adaptation posologique de l'olanzapine. Risque de diminution des concentrations plasmatiques de l'olanzapine et de son efficacite therapeutique, par augmentation de son metabolisme hepatique par la carbamazepine.",
  34. "PC": ""
  35. }
  36. ]
  37. }
  38.  
  39. public SearchableSpinner mySpinner;
  40. private SearchableSpinner mySpinner1;
  41. public ArrayList<Interactions> world = new ArrayList<>();
  42. public final ArrayList<String> mStrings = new ArrayList<>();
  43. public final ArrayList<String> m2Strings = new ArrayList<>();
  44.  
  45. public class DownloadJSON extends AsyncTask<Void, Void, Void> {
  46. @Override
  47. protected Void doInBackground(Void... params) {
  48. // Locate the Interactions Class
  49. jsonobject = JSONfunctions
  50. .getJSONfromURL("https://rabah.000webhostapp.com/data.txt");
  51. try {
  52. // Locate the NodeList name
  53. jsonarray = jsonobject.getJSONArray("interactions");
  54. for (int j = 0; j < jsonarray.length(); j++ ) {
  55. jsonobject = jsonarray.getJSONObject(j);
  56. Interactions worldpop = new Interactions();
  57. worldpop.setMDT1(jsonobject.optString("MDT1"));
  58. worldpop.setMDT2(jsonobject.optString("MDT2"));
  59. worldpop.setPE(jsonobject.optString("PE"));
  60. worldpop.setCI(jsonobject.optString("CI"));
  61. worldpop.setAD(jsonobject.optString("AD"));
  62. worldpop.setPC(jsonobject.optString("PC"));
  63. world.add(worldpop);
  64. // Populate spinner with mdts names
  65. mStrings.add(jsonobject.optString("MDT1"));
  66. m2Strings.add(jsonobject.optString("MDT2"));
  67. }
  68. } catch (Exception e) {
  69. Log.e("Error", e.getMessage());
  70. e.printStackTrace();
  71. }
  72. return null;
  73. }
  74. @Override
  75. protected void onPostExecute(Void args) {
  76. // Spinner adapter
  77. mySpinner.setAdapter(new SimpleListAdapter(MainActivity.this,
  78. android.R.layout.simple_spinner_dropdown_item,
  79. mStrings));
  80. mySpinner1.setAdapter(new SimpleListAdapter(MainActivity.this,
  81. android.R.layout.simple_spinner_dropdown_item,
  82. m2Strings));
  83. }}
  84.  
  85. private OnItemSelectedListener mOnItemSelectedListener = new OnItemSelectedListener() {
  86.  
  87. @Override
  88. public void onItemSelected(View view, int position, long id) {
  89. TextView txtMDT1 = (TextView) findViewById(R.id.MDT1);
  90. txtMDT1.setText("MDT1 : " + world.get(position).getMDT1());
  91.  
  92. TextView txtMDT2 = (TextView) findViewById(R.id.MDT2);
  93. txtMDT2.setText("MDT2 : " + world.get(position).getMDT2());
  94.  
  95.  
  96. String PE = world.get(position).getPE();
  97. String PC = world.get(position).getPC();
  98. String CI = world.get(position).getCI();
  99. String AD = world.get(position).getAD();
  100.  
  101. if (PE!="")
  102. {
  103. TextView txtPE = (TextView) findViewById(R.id.t);
  104. txtPE.setText("PE : " + world.get(position).getPE());
  105. }else if (PC!="") {
  106. TextView txtPc = (TextView) findViewById(R.id.t);
  107. txtPc.setText("Pc : " + world.get(position).getPC());
  108. }
  109. }
  110.  
  111. @Override
  112. public void onNothingSelected() {
  113. Toast.makeText(MainActivity.this, "Nothing Selected", Toast.LENGTH_SHORT).show();
  114. }
  115. };
  116.  
  117. <?xml version="1.0" encoding="utf-8"?>
  118. <RelativeLayout
  119. xmlns:android="http://schemas.android.com/apk/res/android"
  120. xmlns:app="http://schemas.android.com/apk/res-auto"
  121. xmlns:tools="http://schemas.android.com/tools"
  122. android:id="@+id/content_main"
  123. android:layout_width="match_parent"
  124. android:layout_height="match_parent"
  125. android:orientation="vertical"
  126. app:layout_behavior="@string/appbar_scrolling_view_behavior"
  127. tools:context="gr.escsoft.michaelprimez.searchablespinnerexamples.MainActivity"
  128. tools:showIn="@layout/activity_main">
  129.  
  130.  
  131. <gr.escsoft.michaelprimez.searchablespinner.SearchableSpinner
  132. android:id="@+id/mySpinner"
  133. android:layout_width="wrap_content"
  134. android:layout_height="wrap_content"
  135. android:layout_marginTop="24dp"
  136. android:layout_marginLeft="24dp"
  137. android:layout_marginRight="24dp"
  138. android:layout_marginStart="24dp"
  139. android:layout_marginEnd="24dp"
  140. app:RevealEmptyText="Touch to select"
  141. android:gravity="center_horizontal"
  142. app:ShowBorders="true"
  143. app:BordersSize="1dp"
  144. app:BoarderColor="@color/colorPrimary"
  145. app:SpinnerExpandHeight="250dp"/>
  146.  
  147. <gr.escsoft.michaelprimez.searchablespinner.SearchableSpinner
  148. android:layout_height="wrap_content"
  149. android:layout_width="wrap_content"
  150. android:id="@+id/mySpinner1"
  151. app:SpinnerExpandHeight="0dp"
  152. app:BoarderColor="@android:color/holo_blue_light"
  153. app:BordersSize="1dp" app:ShowBorders="true"
  154. android:gravity="center_horizontal"
  155. android:layout_marginEnd="24dp"
  156. android:layout_marginStart="24dp"
  157. android:layout_marginRight="24dp"
  158. android:layout_marginLeft="24dp"
  159. android:layout_marginTop="24dp"
  160. app:RevealEmptyText="Touch to select"
  161. app:SearchViewBackgroundColor="@android:color/holo_blue_light"
  162. app:RevealViewBackgroundColor="@android:color/holo_blue_light"
  163. app:DoneSearchTintColor="@android:color/white"
  164. app:StartSearchTintColor="@android:color/white"
  165. android:layout_below="@+id/mySpinner"/>
  166. <TextView
  167. android:id="@+id/MDT1"
  168. android:layout_width="wrap_content"
  169. android:layout_height="wrap_content"
  170. android:layout_below="@+id/mySpinner1" />
  171. <TextView
  172. android:id="@+id/MDT2"
  173. android:layout_width="wrap_content"
  174. android:layout_height="wrap_content"
  175. android:layout_below="@+id/MDT1" />
  176. <TextView
  177. android:id="@+id/t"
  178. android:layout_width="wrap_content"
  179. android:layout_height="wrap_content"
  180. android:layout_below="@+id/MDT2" />
  181.  
  182.  
  183. </RelativeLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement