Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package info.androidhive.slidingmenu;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import org.apache.http.NameValuePair;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- import android.support.v4.app.*;
- import android.app.Activity;
- import android.app.ProgressDialog;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.os.StrictMode;
- import android.support.v4.app.ListFragment;
- import android.util.Log;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.EditText;
- import android.widget.ListAdapter;
- import android.widget.ListView;
- import android.widget.SimpleAdapter;
- import android.widget.TextView;
- public class PagesFragment extends Fragment
- {
- ….VARIABLES .. and JSON LINK HERE..
- public PagesFragment(){}
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- View rootView = inflater.inflate(R.layout.women_list, container, false);
- list1 = (ListView) rootView.findViewById(R.id.list);
- if (android.os.Build.VERSION.SDK_INT > 9) {
- StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
- StrictMode.setThreadPolicy(policy);
- }
- // new LoadInbox().execute();
- return rootView;
- }
- @Override
- public void onActivityCreated(Bundle savedInstanceState)
- {
- super.onActivityCreated(savedInstanceState);
- // Hashmap for
- inboxList = new ArrayList<HashMap<String, String>>();
- /**
- * Background Async Task to Load all INBOX messages by making HTTP Request
- * */
- Log.d("ITS FUCKING RUNNING BETCH!", "Log Message");
- // LoadInbox().execute();
- new LoadInbox().execute();
- }
- /**
- * Background Async Task to Load all INBOX messages by making HTTP Request
- * */
- class LoadInbox extends AsyncTask<String, String, String> {
- /**
- * Before starting background thread Show Progress Dialog
- * */
- @Override
- protected void onPreExecute () {
- }
- /**
- * getting Inbox JSON
- * */
- protected String doInBackground(String... args) {
- // Building Parameters
- List<NameValuePair> params = new ArrayList<NameValuePair>();
- // getting JSON string from URL
- JSONObject json = jsonParser.makeHttpRequest(INBOX_URL, "GET",
- params);
- // Check your log cat for JSON reponse
- Log.d("Inbox JSON: ", json.toString());
- try {
- inbox = json.getJSONArray(TAG_MESSAGES);
- inbox.toString();
- // looping through All messages
- for (int i = 0; i < inbox.length(); i++) {
- JSONObject c = inbox.getJSONObject(i);
- // Storing each json item in variable
- String id = c.getString(TAG_ID);
- //Get TOURNAMENT NAME
- pt = c.getString(TAG_TOUR);
- tourdate = c.getString(TAG_TOURDATE);
- String from = c.getString(TAG_FROM);
- if(from != null && !from.isEmpty())
- {
- }
- //check if blank
- else{
- from = "--";
- counter++;
- }
- //GET THUR
- String mailer = c.getString(TAG_EMAIL);
- if(mailer != null && !mailer.isEmpty())
- {
- }
- else{ mailer = "--";}
- ///GET ROUND
- String subject = c.getString(TAG_SUBJECT);
- if(subject != null && !subject.isEmpty())
- {
- }
- else{ subject = "--";}
- ///GET SCORE
- String date = c.getString(TAG_DATE);
- if(date != null && !date.isEmpty())
- {
- }
- else{ subject = "--";}
- // creating new HashMap
- HashMap<String, String> map = new HashMap<String, String>();
- // adding each child node to HashMap key => value
- map.put(TAG_ID, id);
- map.put(TAG_FROM, from);
- map.put(TAG_EMAIL, mailer);
- map.put(TAG_DATE, date);
- map.put(TAG_SUBJECT, subject);
- // adding HashList to ArrayList
- inboxList.add(map);
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- return null;
- }
- /**
- * After completing background task Dismiss the progress dialog
- * **/
- protected void onPostExecute(String file_url)
- {
- if( p != null)
- {
- }
- else
- {
- }
- // dismiss the dialog after getting all products
- // pDialog.dismiss();
- // updating UI from Background Threads
- getActivity().runOnUiThread(new Runnable()
- {
- public void run()
- {
- /
- textView = (TextView) getView().findViewById(R.id.textView6);
- textView.setText(" "+ pt + " - " + tourdate);
- /**
- * Updating parsed JSON data into ListView
- * */
- ListAdapter adapter = new SimpleAdapter(
- getActivity(), inboxList,
- R.layout.women_list_item, new String[] { TAG_ID, TAG_FROM,TAG_DATE,TAG_EMAIL,TAG_SUBJECT},
- new int[] { R.id.from, R.id.subject, R.id.date,R.id.mail,R.id.roundscore });
- // updating listview
- list1.setAdapter(adapter);
- }
- });
- }
- //class end
- }
- }
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement