I have a list view in which I adapt a list adapter in order to display some 
items. I have created an arraylist of hashmaps and it seems that the 
adapter recognizes the hashmap objects and saves them on the arraylist but 
they are not passed properly in the adapter. 

*Here is my .java file:*

package com.example.kostas.reslife.activities;

import ...;

public class EventsJSONActivity extends ListActivity {

    private static String url = "http://mob.students.acg.edu/json3.php";;

    public static final String TAG_EVENT_INFO = "eventsinfo";
    public static final String TAG_ID = "id";
    public static final String TAG_TITLE = "title";
    public static final String TAG_DATE = "date";
    public static final String TAG_TIME = "time";
    public static final String TAG_TIME_END = "time_end";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_events_json);

        new GetEvents().execute();
    }

    class GetEvents extends AsyncTask<Void,Void,Void> {
        ArrayList<HashMap<String,String>> eventList;
        ProgressDialog proDialog;

        @Override
        protected void onPreExecute() {
            super.onPreExecute();

            proDialog = new ProgressDialog(EventsJSONActivity.this);
            Log.d("prodialog: ","Setting Message.");
            proDialog.setMessage("Please wait...");
            Log.d("prodialog: ","Setting cancellable.");
            proDialog.setCancelable(false);
            Log.d("prodialog: ","Showing...");
            proDialog.show();
        }

        @Override
        protected Void doInBackground(Void... arg0) {
            WebRequest webreq = new WebRequest();
            String url = "http://mob.students.acg.edu/json3.php";;
            String jsonStr = 
webreq.makeWebServiceCall(url,WebRequest.POSTRequest);

            Log.d("Response: ", "> " + jsonStr);

            eventList = ParseJSON(jsonStr);
            Log.d("eventList info: " , eventList.toString());

            return null;
        }
        
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        @Override
        protected void onPostExecute(Void requestresult) {
            super.onPostExecute(requestresult);

            if (proDialog.isShowing()) {
                proDialog.dismiss();
                Log.d("prodialog: ","dismissing dialog.");
            }

            Log.d("Listadapter: ", "eventList: " + eventList.toString());
            ListAdapter adapter = new SimpleAdapter(
                    EventsJSONActivity.this,eventList,
                    android.R.layout.simple_list_item_1,
                    new String[] {TAG_ID, TAG_TITLE, TAG_DATE, TAG_TIME, 
TAG_TIME_END},
                    new int[] 
{R.id.id,R.id.title,R.id.date,R.id.time,R.id.time_end});
            Log.d("Listadapter: ","data fed");
            ListView lv = (ListView)findViewById(android.R.id.list);
            lv.setAdapter(adapter);
            Log.d("Listadapter: ",adapter.getCount() + " items set");

        
}//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!


        private ArrayList<HashMap<String,String>> ParseJSON(String json) {

            if (json != null) {
                try {
                    ArrayList<HashMap<String,String>> eventList = new 
ArrayList<>();
                    JSONObject jsonObj = new JSONObject(json);

                    JSONArray events = jsonObj.getJSONArray(TAG_EVENT_INFO);

                    for (int i = 0; i < events.length(); i++) {
                        JSONObject j = events.getJSONObject(i);

                        String id = j.getString(TAG_ID);
                        String title = j.getString(TAG_TITLE);
                        String date = j.getString(TAG_DATE);
                        String time = j.getString(TAG_TIME);
                        String time_end = j.getString(TAG_TIME_END);

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

                        event.put(TAG_ID,id);
                        event.put(TAG_TITLE,title);
                        event.put(TAG_DATE,date);
                        event.put(TAG_TIME,time);
                        event.put(TAG_TIME_END,time_end);

                        /*event.put(TAG_ID,"id");
                        event.put(TAG_TITLE,"title");
                        event.put(TAG_DATE,"date");
                        event.put(TAG_TIME,"time");
                        event.put(TAG_TIME_END,"time_end");*/

                        eventList.add(event);
                    }
                    Log.d("EventList > ", eventList.toString());
                    return eventList;

                } catch (JSONException e) {
                    e.printStackTrace();
                    return null;
                }
            } else {
                Log.e("ServiceHandler", "No data received from HTTP 
Request");
                return null;
            }
        }
    }


}

*And here is my .xml file*

<?xml version="1.0" encoding="utf-8"?> <LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"; 
android:layout_width="match_parent" android:layout_height="match_parent" 
android:orientation="vertical"> <ListView android:id="@android:id/list" 
android:layout_width="match_parent" android:layout_height="match_parent"> 
</ListView> <TextView android:id="@+id/id" 
android:layout_width="fill_parent" android:layout_height="wrap_content" 
android:paddingBottom="2dip" android:paddingTop="6dip" 
android:textSize="16sp"/> <TextView android:id="@+id/title" 
android:layout_width="fill_parent" android:layout_height="wrap_content" 
android:paddingBottom="2dip" /> <TextView android:id="@+id/date" 
android:layout_width="fill_parent" android:layout_height="wrap_content" 
android:gravity="start"/> <TextView android:id="@+id/time" 
android:layout_width="fill_parent" android:layout_height="wrap_content" 
android:gravity="start" /> <TextView android:id="@+id/time_end" 
android:layout_width="fill_parent" android:layout_height="wrap_content" 
android:gravity="start" /> </LinearLayout>

-- 
You received this message because you are subscribed to the Google Groups 
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-developers/66a57304-dc40-4d90-8b94-7ac94c1f07c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to