Hi All,
I am working on json parsing
i need help on sample code for passing the  parsed data to list view
without
can any one help me for this

here is my following code i am unable to display the list
package com.incipio.bespoke;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHttpResponse;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class FB_TWListActivity extends ListActivity {
    ArrayList<HashMap<String, String>> mylist = new
ArrayList<HashMap<String, String>>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stubg
        super.onCreate(savedInstanceState);
        FaceBookTask facebooktask = new
FaceBookTask(FB_TWListActivity.this);
        facebooktask.execute(null);
        Log.d("fblist", "fb list");
        setContentView(R.layout.fb_twlistxml);
        Log.d("fblist", "fb list               3");
        ListAdapter adapter = new SimpleAdapter(this, mylist,
R.layout.fb_twtv,
                new String[] { "name", "message", "link" }, new int[] {
                        R.id.textView1, R.id.textView2, R.id.textView3 });
        Log.d("fblist", "fb list               4");
        setListAdapter(adapter);

        final ListView lv = getListView();
        lv.setTextFilterEnabled(true);
        lv.setCacheColorHint(Color.TRANSPARENT);

    }

    JSONObject from;
    String str_name, message, link;

    HashMap<String, String> listItems = new HashMap<String, String>();

    class FaceBookTask extends AsyncTask<JSONObject, Void, JSONObject> {
        ProgressDialog progressDialog = null;

        public FaceBookTask(Context context) {
            // TODO Auto-generated constructor stub
            progressDialog = new ProgressDialog(context);
        }

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            progressDialog.setMessage("Getting edit......");
            progressDialog.show();
            super.onPreExecute();
        }

        @Override
        protected void onProgressUpdate(Void... values) {
            // TODO Auto-generated method stub
            super.onProgressUpdate(values);
        }

        @Override
        protected void onPostExecute(JSONObject result) {
            // TODO Auto-generated method stub
            if (progressDialog.isShowing()) {

                progressDialog.dismiss();
            }
            super.onPostExecute(result);
        }

        @Override
        protected JSONObject doInBackground(JSONObject... arg0) {
            // TODO Auto-generated method stub
            HttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(
                    "http://ncpo.cc/mashup/facebookfeed.php";);

            List nameValuePairs = new ArrayList();
            nameValuePairs.add(new BasicNameValuePair("name",
                    AboutUsActivity.name));

            try {
                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs,
                        "UTF-8"));

                /*
                 * processing http request
                 */
                BasicHttpResponse httpResponse;

                httpResponse = (BasicHttpResponse)
httpClient.execute(httpPost);

                /*
                 * processing to get basic response
                 */
                BasicResponseHandler handler = new BasicResponseHandler();
                String response = handler.handleResponse(httpResponse);
                Log.d("Facebooktask", "EDIT RESPONSE " + response);

                try {
                    JSONObject json_response = new JSONObject(response);
                    Log.d("Facebooktask", "json_response " + json_response);

                    String data = new String(response);
                    Log.d("Facebooktask", "String data " + data);

                    JSONArray data1 = json_response.getJSONArray("data");
                    Log.d("about us", "data1" + data1);

                    for (int i = 0; i < data1.length(); i++) {
                        try {
                            String id =
data1.getJSONObject(i).getString("id");

                            Log.d("about us", "id" + id);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        try {
                            from =
data1.getJSONObject(i).getJSONObject("from");

                            Log.d("about us", "from" + from);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        try {
                            str_name = from.getString("name");
                            listItems.put("name", str_name);
                            Log.d("about us", "name" + str_name);

                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        try {
                            message = data1.getJSONObject(i).getString(
                                    "message");
                            listItems.put("message", message);
                            Log.d("about us", "message" + message);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        try {
                            link = data1.getJSONObject(i).getString("link");
                            listItems.put("link", link);
                            Log.d("about us", "link" + link);
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }

                        mylist.add(listItems);
                    }

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }
    }

}


Thanks
Naveen

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to