I could successfully get the Json values by using the method explained
by Jose...
Thanks to Jose once again. Now i m trying to display all the values of
the Json into a list view using the adapters. But i m getting a null
pointer exception while running the app... Can anyone tell me what the
problem is...
Here's the code...

public class AlertsPage extends Activity{
        ListView lv;

        @Override

                public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                        setContentView(R.layout.alerts);
                        lv=(ListView)findViewById(R.id.list);

                       WebService webService = new WebService("http://
www.sumasoftware.com/alerts/GetAlerts.php");


                        Map<String, String> params = new HashMap<String, 
String>();
                        params.put("var", "");
                        String response = webService.webGet("", params);

                        try
                        {
                                Type collectionType = new 
TypeToken<List<Alerts>>(){}.getType();
                                List<Alerts> alrt = new 
Gson().fromJson(response, collectionType);
                                Log.e("Alert",alrt.toString());
                                lv.setAdapter(new 
AlertsAdapter(getBaseContext(),alrt));
                        }
                        catch(Exception e)
                        {
                                Log.d("Error: ", e.getMessage());
                        }
        }
}




public class AlertsAdapter extends BaseAdapter {
        private Context mContext;
        private List<Alerts>  alerts = new ArrayList<Alerts>();
        public AlertsAdapter(Context context, List<Alerts> alrt) {
             mContext = context;
             alerts = alrt;
        }

        @Override
        public int getCount() {
                // TODO Auto-generated method stub
                return alerts.size();

        }

        @Override
        public Object getItem(int position) {
                // TODO Auto-generated method stub
                return alerts.get(position);
        }

        @Override
        public long getItemId(int position) {
                // TODO Auto-generated method stub
                return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent)
{
                // TODO Auto-generated method stub
                Activity activity = new Activity();
        LayoutInflater inflater = activity.getLayoutInflater();
        View rowView = inflater.inflate(R.layout.list_text, null);
        JSONObject imageAndText = (JSONObject) getItem(position);
        TextView textView = (TextView)
rowView.findViewById(R.id.last_build_stat);
        try {
                        textView.setText((String)imageAndText.get("alerttext"));
                } catch (JSONException e) {
                        textView.setText("JSON Exception");
                }

        return rowView;
    }

        }


Plz tell me am i using the correct adapters and correct implementation
to display the values in list view???

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

Reply via email to