Advertisement
minafaw3

Diases_Fragment

Oct 7th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1.  
  2. import java.util.ArrayList;
  3.  
  4. import leaynik.api.API;
  5. import leaynik.api.JsonParsing;
  6.  
  7. import org.json.JSONArray;
  8. import org.json.JSONException;
  9.  
  10. import Le3ynik.defs.ConnectionExector.HTTPResponse;
  11. import Le3ynik.defs.ConnectionExector.ResponseType;
  12. import Le3ynik.defs.ConnectionExector.onHttpRequestListener;
  13. import Le3ynik.defs.DisasesItem;
  14. import Le3ynik.ui.Disases_listView;
  15. import android.content.Intent;
  16. import android.os.Bundle;
  17. import android.support.v4.app.Fragment;
  18. import android.view.LayoutInflater;
  19. import android.view.View;
  20. import android.view.View.OnClickListener;
  21. import android.view.ViewGroup;
  22. import android.widget.AdapterView;
  23. import android.widget.AdapterView.OnItemClickListener;
  24. import android.widget.ListView;
  25. import android.widget.ProgressBar;
  26. import android.widget.TextView;
  27. import android.widget.Toast;
  28.  
  29. import com.gruposca.android.floatingview.ui.views.FloatingView;
  30.  
  31. public class Diases_Fragment extends Fragment {
  32.  
  33. public static Diases_Fragment newInstance() {
  34. Diases_Fragment fragment = new Diases_Fragment();
  35. Bundle args = new Bundle();
  36.  
  37. return fragment;
  38. }
  39.  
  40. Disases_listView Adapter;
  41. ListView list;
  42. ProgressBar progress;
  43. ArrayList<DisasesItem> Disases = new ArrayList<DisasesItem>();
  44.  
  45. TextView reload;
  46.  
  47. @Override
  48. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  49. Bundle savedInstanceState) {
  50.  
  51. View v = inflater.inflate(R.layout.listview, null);
  52. list = (ListView) v.findViewById(R.id.zfta);
  53. progress = (ProgressBar) v.findViewById(R.id.list_prog);
  54. Adapter = new Disases_listView(getActivity(), Disases);
  55. reload = (TextView) v.findViewById(R.id.reload);
  56.  
  57. list.setAdapter(Adapter);
  58. list.setOnItemClickListener(new OnItemClickListener() {
  59.  
  60. @Override
  61. public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
  62. long arg3) {
  63.  
  64. // Intent i = new Intent(getActivity(), Disase_Details.class);
  65. // i.putExtra("mard", Disases.get(pos));
  66. // startActivity(i);
  67. // Disase_Details details = new Disase_Details();
  68. // ((Home) getActivity()).replaceDieasesFragment(details,
  69. // Disases.get(pos));
  70. Intent i = new Intent(getActivity(), Disase_Details.class);
  71. i.putExtra("mard", Disases.get(pos));
  72. startActivity(i);
  73.  
  74. }
  75. });
  76. GetAllDiases();
  77. reload.setOnClickListener(new OnClickListener() {
  78.  
  79. @Override
  80. public void onClick(View arg0) {
  81.  
  82. GetAllDiases();
  83.  
  84. }
  85. });
  86. final FloatingView floatinView = (FloatingView) v
  87. .findViewById(R.id.FloatingView);
  88. if (floatinView != null) {
  89. floatinView.setScrollableViewId(R.id.zfta);
  90. floatinView.setVisibility(View.GONE);
  91. }
  92.  
  93. return v;
  94. }
  95.  
  96. private void GetAllDiases() {
  97.  
  98. API api = new API(getActivity());
  99. if (api.isNetworkConnected()) {
  100. progress.setVisibility(View.VISIBLE);
  101. list.setVisibility(View.GONE);
  102. reload.setVisibility(View.GONE);
  103. api.getAllDisease(onGetAllDiases);
  104. } else {
  105. Toast.makeText(getActivity(),
  106. getResources().getString(R.string.nointernet), 2000).show();
  107. list.setVisibility(View.GONE);
  108. reload.setVisibility(View.VISIBLE);
  109.  
  110. }
  111.  
  112. }
  113.  
  114. onHttpRequestListener onGetAllDiases = new onHttpRequestListener() {
  115.  
  116. @Override
  117. public void onHttpResult(HTTPResponse response, String senddata) {
  118. progress.setVisibility(View.GONE);
  119. list.setVisibility(View.VISIBLE);
  120. if (response.response == ResponseType.SUCESS) {
  121. try {
  122. JSONArray arr = (JSONArray) response.data;
  123. JsonParsing json = new JsonParsing();
  124. for (int i = 0; i < arr.length(); i++)
  125. Disases.add(json.GetDisesInfo(arr.getJSONObject(i)));
  126. Adapter.notifyDataSetChanged();
  127. } catch (JSONException e) {
  128. e.printStackTrace();
  129. }
  130.  
  131. } else {
  132.  
  133. }
  134.  
  135. }
  136. };
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement