package in.co.sdslabs.cognizance;

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

import android.database.SQLException;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.SimpleAdapter;

public class EventCategoryFragment extends ListFragment {

	// private ListView mEventList;
	private List<HashMap<String, String>> eventList;
	private SimpleAdapter mAdapter;

	private String EVENTNAME = "eventname";
	private String EVENTVENUE = "eventvenue";
	private String EVENTTIME = "eventtime";

	public EventCategoryFragment() {
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// Retrieving the currently selected item number
		int position = getArguments().getInt("position");

		String[] categories = getResources().getStringArray(
				R.array.eventCategories);

		// Creating view correspoding to the fragment
		View v = inflater.inflate(R.layout.eventcategoryfragment_layout,
				container, false);

		eventList = new ArrayList<HashMap<String, String>>();

		// Initialising DBhelper class

		DatabaseHelper myDbHelper = new DatabaseHelper(getActivity()
				.getBaseContext());
		try {
			myDbHelper.createDataBase();
		} catch (IOException ioe) {
			throw new Error("Unable to create database");
		}

		try {
			myDbHelper.openDataBase();
		} catch (SQLException sqle) {
			throw sqle;
		}
		// TextView tv = (TextView) v.findViewById(R.id.tv_categoryDescription);
		// tv.setText(categories[position]);
		// mEventList = (ListView) v.findViewById(R.id.eventCategory_list);

		/** Create function in DBhelper to return these three values **/
		// String Data = DBhelper.getReducedEvent(categories[position]);
		for (int i = 0; i < 20; i++) {
			HashMap<String, String> hm = new HashMap<String, String>();
			hm.put(EVENTNAME, "");
			hm.put(EVENTVENUE, "");
			hm.put(EVENTTIME, "");
			// hm.put(IMAGE, Integer.toString(mImages[i]));
			eventList.add(hm);
		}

		String[] from = { EVENTNAME ,EVENTVENUE , EVENTTIME};

		int[] to = { R.id.tv_eName, R.id.tv_eVenue, R.id.tv_eTime };

		// Instantiating an adapter to store each items
		// R.layout.drawer_layout defines the layout of each item
		mAdapter = new SimpleAdapter(getActivity().getBaseContext(), eventList,
				R.layout.eventcategory_list_item, from, to);

		setListAdapter(mAdapter);

		return v;
	}

}
@@ -371,16 +371,48 @@
 Adapter;
+%0Aimport android.widget.TextView;
 %0A%0Apublic
@@ -705,16 +705,55 @@
 nttime%22;
+%0A%09%0A%09int position;%0A%09String%5B%5D categories;
 %0A%0A%09publi
@@ -991,20 +991,16 @@
 umber%0A%09%09
-int 
 position
@@ -1040,25 +1040,16 @@
 n%22);%0A%0A%09%09
-String%5B%5D 
 categori
@@ -1253,16 +1253,18 @@
 false);%0A
+%09%09
 %0A%09%09event
@@ -1831,16 +1831,53 @@
 _list);%0A
+%09%09// getListView().addHeaderView(tv);
 %0A%09%09/** C
@@ -2617,48 +2617,510 @@
 %0A%0A%09%09
-setListAdapter(mAdapter);%0A%0A%09%09return v;%0A%09
+return v;%0A%09%7D%0A%0A%09@Override%0A%09public void onViewCreated(View view, Bundle savedInstanceState) %7B%0A%09%09// TODO Auto-generated method stub%0A%09%09super.onViewCreated(view, savedInstanceState);%0A%09%09%09%09%0A%09%09TextView listHeader = new TextView(getActivity());%0A%09%09listHeader.setTextSize(30);%0A%09%09listHeader.setText(categories%5Bposition%5D);%0A%09%09getListView().addHeaderView(listHeader);%0A%09%09%0A%09%09setListAdapter(mAdapter);%0A%09%7D%0A%09%0A    @Override%0A    public void onDestroyView() %7B%0A        super.onDestroyView();%0A        setListAdapter(null);%0A    
 %7D%0A%0A%7D

Add header to display category description to listView