Advertisement
Guest User

Untitled

a guest
Sep 21st, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.80 KB | None | 0 0
  1. package info.androidhive.slidingmenu;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6.  
  7. import org.apache.http.NameValuePair;
  8. import org.json.JSONArray;
  9. import org.json.JSONException;
  10. import org.json.JSONObject;
  11. import android.support.v4.app.*;
  12.  
  13. import android.app.Activity;
  14. import android.app.ProgressDialog;
  15. import android.os.AsyncTask;
  16. import android.os.Bundle;
  17. import android.os.StrictMode;
  18. import android.support.v4.app.ListFragment;
  19. import android.util.Log;
  20. import android.view.LayoutInflater;
  21. import android.view.View;
  22. import android.view.ViewGroup;
  23. import android.widget.EditText;
  24. import android.widget.ListAdapter;
  25. import android.widget.ListView;
  26. import android.widget.SimpleAdapter;
  27. import android.widget.TextView;
  28.  
  29. public class PagesFragment extends Fragment
  30. {
  31.  
  32. ….VARIABLES .. and JSON LINK HERE..
  33.  
  34.  
  35. public PagesFragment(){}
  36.  
  37. @Override
  38. public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  39. View rootView = inflater.inflate(R.layout.women_list, container, false);
  40. list1 = (ListView) rootView.findViewById(R.id.list);
  41.  
  42. if (android.os.Build.VERSION.SDK_INT > 9) {
  43. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
  44. StrictMode.setThreadPolicy(policy);
  45. }
  46. // new LoadInbox().execute();
  47. return rootView;
  48. }
  49.  
  50.  
  51. @Override
  52. public void onActivityCreated(Bundle savedInstanceState)
  53. {
  54. super.onActivityCreated(savedInstanceState);
  55. // Hashmap for
  56. inboxList = new ArrayList<HashMap<String, String>>();
  57. /**
  58. * Background Async Task to Load all INBOX messages by making HTTP Request
  59. * */
  60.  
  61. Log.d("ITS FUCKING RUNNING BETCH!", "Log Message");
  62. // LoadInbox().execute();
  63. new LoadInbox().execute();
  64.  
  65. }
  66.  
  67. /**
  68. * Background Async Task to Load all INBOX messages by making HTTP Request
  69. * */
  70. class LoadInbox extends AsyncTask<String, String, String> {
  71.  
  72. /**
  73. * Before starting background thread Show Progress Dialog
  74. * */
  75. @Override
  76. protected void onPreExecute () {
  77.  
  78. }
  79.  
  80. /**
  81. * getting Inbox JSON
  82. * */
  83. protected String doInBackground(String... args) {
  84. // Building Parameters
  85. List<NameValuePair> params = new ArrayList<NameValuePair>();
  86.  
  87. // getting JSON string from URL
  88. JSONObject json = jsonParser.makeHttpRequest(INBOX_URL, "GET",
  89. params);
  90.  
  91. // Check your log cat for JSON reponse
  92. Log.d("Inbox JSON: ", json.toString());
  93.  
  94. try {
  95. inbox = json.getJSONArray(TAG_MESSAGES);
  96.  
  97.  
  98. inbox.toString();
  99.  
  100. // looping through All messages
  101. for (int i = 0; i < inbox.length(); i++) {
  102. JSONObject c = inbox.getJSONObject(i);
  103.  
  104. // Storing each json item in variable
  105. String id = c.getString(TAG_ID);
  106.  
  107. //Get TOURNAMENT NAME
  108. pt = c.getString(TAG_TOUR);
  109.  
  110.  
  111. tourdate = c.getString(TAG_TOURDATE);
  112.  
  113.  
  114. String from = c.getString(TAG_FROM);
  115.  
  116. if(from != null && !from.isEmpty())
  117. {
  118.  
  119.  
  120. }
  121.  
  122. //check if blank
  123. else{
  124.  
  125. from = "--";
  126.  
  127. counter++;
  128.  
  129. }
  130.  
  131. //GET THUR
  132. String mailer = c.getString(TAG_EMAIL);
  133.  
  134. if(mailer != null && !mailer.isEmpty())
  135. {
  136.  
  137. }
  138. else{ mailer = "--";}
  139.  
  140.  
  141. ///GET ROUND
  142.  
  143. String subject = c.getString(TAG_SUBJECT);
  144.  
  145. if(subject != null && !subject.isEmpty())
  146. {
  147.  
  148.  
  149. }
  150.  
  151. else{ subject = "--";}
  152.  
  153.  
  154. ///GET SCORE
  155.  
  156. String date = c.getString(TAG_DATE);
  157.  
  158. if(date != null && !date.isEmpty())
  159. {
  160.  
  161.  
  162. }
  163.  
  164. else{ subject = "--";}
  165.  
  166.  
  167.  
  168. // creating new HashMap
  169. HashMap<String, String> map = new HashMap<String, String>();
  170.  
  171. // adding each child node to HashMap key => value
  172. map.put(TAG_ID, id);
  173. map.put(TAG_FROM, from);
  174. map.put(TAG_EMAIL, mailer);
  175. map.put(TAG_DATE, date);
  176. map.put(TAG_SUBJECT, subject);
  177.  
  178.  
  179. // adding HashList to ArrayList
  180. inboxList.add(map);
  181. }
  182.  
  183. } catch (JSONException e) {
  184. e.printStackTrace();
  185. }
  186.  
  187. return null;
  188. }
  189.  
  190.  
  191. /**
  192. * After completing background task Dismiss the progress dialog
  193. * **/
  194.  
  195. protected void onPostExecute(String file_url)
  196. {
  197.  
  198. if( p != null)
  199. {
  200. }
  201. else
  202. {
  203.  
  204. }
  205.  
  206. // dismiss the dialog after getting all products
  207. // pDialog.dismiss();
  208. // updating UI from Background Threads
  209.  
  210. getActivity().runOnUiThread(new Runnable()
  211. {
  212. public void run()
  213. {
  214.  
  215. /
  216. textView = (TextView) getView().findViewById(R.id.textView6);
  217. textView.setText(" "+ pt + " - " + tourdate);
  218.  
  219. /**
  220. * Updating parsed JSON data into ListView
  221. * */
  222.  
  223. ListAdapter adapter = new SimpleAdapter(
  224. getActivity(), inboxList,
  225. R.layout.women_list_item, new String[] { TAG_ID, TAG_FROM,TAG_DATE,TAG_EMAIL,TAG_SUBJECT},
  226. new int[] { R.id.from, R.id.subject, R.id.date,R.id.mail,R.id.roundscore });
  227. // updating listview
  228. list1.setAdapter(adapter);
  229.  
  230.  
  231. }
  232.  
  233. });
  234.  
  235.  
  236. }
  237.  
  238. //class end
  239. }
  240.  
  241. }
  242. //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement