package com.example.GPS_DB01;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

import java.util.List;

import android.app.Activity;

public class NewActivity extends Activity 
{

	private DAOtextReport daOtextReport;
	
	@Override
	public void onCreate(Bundle savedInstanceState) 
	{
			super.onCreate(savedInstanceState);
			// Get the view from new_activity.xml
			setContentView(R.layout.listview_layout);
	}
	
	
	@Override protected void onResume() 
	{
	        super.onResume();
	
	        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getList());
	        ListView listView = (ListView) findViewById(R.id.my_listview);
	        listView.setAdapter(adapter);
	        addItemClickListener(listView);
    }

   
    public String[] getList() 
    {
	        daOtextReport = new DAOtextReport(getApplicationContext());
	        List<TextReport> alist = daOtextReport.getAllTextReports();
	        
	        String aaa = alist.get(0).toString();
	        
	        String[] list = new String[alist.size()];
	        for (int i = 0; i < alist.size(); i++) 
	        {
	            list[i] = alist.get(i).toString();
	        }
	        
	        daOtextReport.close();
	        return list;
    }
    
    
    private void addItemClickListener(final ListView listView)
    {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() 
        {
	            @Override 
	            public void onItemClick(AdapterView<?> parent, View view, int position, long id)
	            {
	                String itemValue = (String) listView.getItemAtPosition(position);
	                Toast.makeText(getApplicationContext(), "Position: " + position + " item: " + itemValue, Toast.LENGTH_SHORT).show();
	            }
        });
    }
	
}