Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid reading a csv
    primarykey
    data
    text
    <p>I made a simple application that will log a user input from an editText and it will put it into a csv on my sdcard. Now my problem is reading that csv and making it as a variable for the next activity on my app.</p> <p>Here is my main activity:</p> <pre><code>package com.willardcuizon.differentialgps; import java.io.File; import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.app.Activity; import android.content.Context; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class Main extends Activity implements OnClickListener{ Button start; EditText lat; EditText lon; LocationListener loclist; CSVFileWriter csv; StringBuffer filePath; File file; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); start = (Button) findViewById(R.id.button1); start.setOnClickListener(this); lat = (EditText) findViewById(R.id.editText1); lon = (EditText) findViewById(R.id.editText2); filePath = new StringBuffer(); filePath.append("/sdcard/surveyedGPS.csv"); file = new File(filePath.toString()); csv = new CSVFileWriter(file); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public void onClick(View v) { // TODO Auto-generated method stub if(v.getId()==R.id.button1){ LocationManager locman = (LocationManager)getSystemService(Context.LOCATION_SERVICE); if(locman.isProviderEnabled(LocationManager.GPS_PROVIDER)){ Toast.makeText( getApplicationContext(), "GPS is Enabled.", Toast.LENGTH_SHORT ).show(); csv.writeHeader(lat.getText().toString()); csv.writeHeader(lon.getText().toString()); } else{ Toast.makeText( getApplicationContext(), "GPS is Disabled.Please enable GPS", Toast.LENGTH_SHORT ).show(); } } } } </code></pre> <p>And here is my CSVWriter Class:</p> <pre><code>package com.willardcuizon.differentialgps; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class CSVFileWriter { private PrintWriter csvWriter; private File file; public CSVFileWriter(File file) { this.file = file; } public void writeHeader(String data) { try { if (data != null) { csvWriter = new PrintWriter(new FileWriter(file, true)); csvWriter.print(","); csvWriter.print(data); csvWriter.close(); } } catch (IOException e) { e.printStackTrace(); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload