package com.andela.motustracker;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CursorAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.Toast;

import com.andela.motustracker.dbParser.DbCursorAdapter;
import com.andela.motustracker.helper.AppContext;
import com.andela.motustracker.manager.DbManager;
import com.andela.motustracker.model.LocationData;

import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class LocationListFragment extends Fragment {
    private Spinner spinner;
    private ListView listView;


    public LocationListFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_location_list, container, false);

        spinner = (Spinner) view.findViewById(R.id.id_spinnerView);
        SpinnerAdapter spinnerAdapter = ArrayAdapter.createFromResource(AppContext.get(),
                R.array.spinnerDropDown, R.layout.spinner_custom_view);
        spinner.setAdapter(spinnerAdapter);

        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                String item = parent.getItemAtPosition(position).toString();
                //final String ad = getResources().getString(R.string.list_by_name);
                switch (item) {
                    case "List By Day":
                        //List location by day in the ListView
                        break;
                    case "List By Time Spent":
                        //List location by time spent in the ListView
                        break;
                }

                // Showing selected spinner item

            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

        listView = (ListView) view.findViewById(R.id.id_frag_listView);
        DbCursorAdapter adapter = new DbCursorAdapter(new DbManager().readDataFromDb(),0);
        listView.setAdapter(adapter);
        return view;
    }

}

@@ -191,39 +191,8 @@
 up;%0A
-import android.widget.Adapter;%0A
 impo
@@ -262,45 +262,8 @@
 er;%0A
-import android.widget.CursorAdapter;%0A
 impo
@@ -362,37 +362,8 @@
 ter;
-%0Aimport android.widget.Toast;
 %0A%0Aim
@@ -402,22 +402,20 @@
 arser.Db
-Cursor
+List
 Adapter;
@@ -584,16 +584,21 @@
 va.util.
+Array
 List;%0A%0A%0A
@@ -757,16 +757,55 @@
 stView;%0A
+    private DbListAdapter listAdapter;%0A
 %0A%0A    pu
@@ -1446,16 +1446,294 @@
 apter);%0A
+        listView = (ListView) view.findViewById(R.id.id_frag_listView);%0A        listAdapter = new DbListAdapter(getContext(),R.layout.fragment_location_list,%0A                R.id.id_userLatitudeText, new DbManager().readDataFromDb());%0A        listView.setAdapter(listAdapter);%0A%0A
 %0A       
@@ -2192,194 +2192,586 @@
     
-//List location by day in the ListView%0A                        break;%0A                    case %22List By Time Spent%22:%0A                        //List location by time spent in the ListView
+listAdapter.clear();%0A                        listAdapter.addNewDataToList(new DbManager().readDataFromDb());%0A                        listAdapter.notifyDataSetChanged();%0A                        break;%0A                    case %22List By Time Spent%22:%0A                        //List location by time spent in the ListView%0A                        listAdapter.clear();%0A                        ArrayList%3CLocationData%3E data = new DbManager().readListBaseOnLocation();%0A                        listAdapter.addNewDataToList(data);%0A                        listAdapter.notifyDataSetChanged();
 %0A   
@@ -3003,208 +3003,8 @@
 );%0A%0A
-        listView = (ListView) view.findViewById(R.id.id_frag_listView);%0A        DbCursorAdapter adapter = new DbCursorAdapter(new DbManager().readDataFromDb(),0);%0A        listView.setAdapter(adapter);
 %0A   

Implement the List Adapter in the LocationListFragment