@Override public void onCreate(Bundle savedInstanceState) { context = this; super.onCreate(savedInstanceState); setContentView(R.layout.location_list_layout); GameDBHelper mDBHelper = new GameDBHelper(getBaseContext()); SQLiteDatabase db = mDBHelper.getWritableDatabase(); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // *********************************************************************************** // These values will be used for a CursorAdapter technique for populating the ListView // *********************************************************************************** String[] projection = { BaseColumns._ID, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_ID, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LOCATION_NAME, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_DESCRIPTION, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LATITUDE, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LONGITUDE, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_DATE }; String sortOrder = BaseColumns._ID + " DESC"; c = db.query( ContractCoordinates.CoordinatesEntry.TABLE_NAME, projection, null, null, null, null, sortOrder); ListView listview = (ListView) findViewById(R.id.myCoordinateList); if (c != null) { c.moveToFirst(); String[] fromColumns = { ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LOCATION_NAME, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LATITUDE, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LONGITUDE }; int[] toViews = {R.id.location_name, R.id.location_lat, R.id.location_lng}; SimpleCursorAdapter ca = new SimpleCursorAdapter( getBaseContext(), R.layout.coordinate_item_layout, c, fromColumns, toViews, 1); listview.setAdapter(ca); } db.close(); // ****************************** // Add the adaptor to my ListView // ****************************** // ListView listview = (ListView)findViewById(R.id.myCoordinateList); listview.setOnItemClickListener(mMessageClickedHandler); listview.setOnItemLongClickListener(mMessageLongClickedHandler); }
// create a csv file of the different locations, and export it as an attachment to an email public void exportList(View v) { // Construct the csv file from the database GameDBHelper mDBHelper = new GameDBHelper(getBaseContext()); SQLiteDatabase db = mDBHelper.getReadableDatabase(); // *********************************************************************************** // These values will be used for a CursorAdapter technique for populating the ListView // *********************************************************************************** String[] projection = { BaseColumns._ID, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_ID, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LOCATION_NAME, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_DESCRIPTION, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LATITUDE, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LONGITUDE, ContractCoordinates.CoordinatesEntry.COLUMN_NAME_DATE }; String sortOrder = BaseColumns._ID + " DESC"; Cursor c2 = db.query( ContractCoordinates.CoordinatesEntry.TABLE_NAME, projection, null, null, null, null, sortOrder); c2.moveToFirst(); String dataString = ""; // = "\"" + "test location" +"\",\"" + "test lat" + "\",\"" + "test long" + "\""; for (int i = 0; i < c2.getCount(); i++) { dataString = dataString + "\"" + c2.getString( c.getColumnIndex(ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LOCATION_NAME)) + "\",\"" + c2.getString( c.getColumnIndex(ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LATITUDE)) + "\",\"" + c2.getString( c.getColumnIndex(ContractCoordinates.CoordinatesEntry.COLUMN_NAME_LONGITUDE)) + "\"" + "\n"; c2.moveToNext(); } db.close(); String columnString = "\"Place\",\"Latitude\",\"Longitude\""; String combinedString = columnString + "\n" + dataString; File file = null; File root = Environment.getExternalStorageDirectory(); if (root.canWrite()) { File dir = new File(root.getAbsolutePath() + "/PersonData"); dir.mkdirs(); file = new File(dir, "Data.csv"); FileOutputStream out = null; try { out = new FileOutputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } try { out.write(combinedString.getBytes()); } catch (IOException e) { e.printStackTrace(); } try { out.close(); } catch (IOException e) { e.printStackTrace(); } } Uri u1 = null; u1 = Uri.fromFile(file); Intent sendIntent = new Intent(Intent.ACTION_SEND); sendIntent.putExtra(Intent.EXTRA_SUBJECT, "LatLong List"); sendIntent.putExtra(Intent.EXTRA_STREAM, u1); sendIntent.setType("text/html"); startActivity(sendIntent); }