I have been searching for methods to display the values in my csv files to the Android Applications but were not successful. ( I am a totally beginner for JAVA and Android )
Each time I took the codes to be modified from the internet, my system will either not working( Test.apk has stopped working ) or totally displaying nothing in the apk.
An overview of my eclipse Java perspective is in the following picture.
https://i.stack.imgur.com/kQqyM.png
1 of the codes that I used in my program ( Inside my Test.java ):
package com.test;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.view.Menu;
import au.com.bytecode.opencsv.CSVReader;
public class TEST extends Activity {
private List<String[]> readCsv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.test, menu);
return true;
}
public final List<String[]> readCsv(Context context) {
List<String[]> questionList = new ArrayList<String[]>();
AssetManager assetManager = context.getAssets();
try {
InputStream csvStream = assetManager.open("Velox-I OBDH.csv");
InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
CSVReader csvReader = new CSVReader(csvStreamReader);
String[] line;
// throw away the header
csvReader.readNext();
while ((line = csvReader.readNext()) != null) {
questionList.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return questionList;
}
The 2nd code I used which ends up not working
package com.test;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.content.res.AssetManager;
import android.os.Bundle;
import android.view.Menu;
import au.com.bytecode.opencsv.CSVReader;
public class TEST extends Activity {
public final List<String[]> readCsv(Context context) {
List<String[]> questionList = new ArrayList<String[]>();
AssetManager assetManager = context.getAssets();
try {
InputStream csvStream = assetManager.open("Velox-I OBDH.csv");
InputStreamReader csvStreamReader = new InputStreamReader(csvStream);
CSVReader csvReader = new CSVReader(csvStreamReader);
String[] line;
// throw away the header
csvReader.readNext();
while ((line = csvReader.readNext()) != null) {
questionList.add(line);
}
} catch (IOException e) {
e.printStackTrace();
}
return questionList;
}
For your all information, I am using Eclipse to develop my Android Application and I did included openCSV.jar in my libs also. So my question is :
How can I displaying all the values of my 8 csv files into 8 different activities?
When I had the csv reader code, how do I put it into the Java class and connect it to the xml or android such that the values in csv can be displayed.
some of the examples of the values in the csv files:
920004,"PSAT_XBP_Channel_Mask" 920006,"PSAT_XBP_Scan_Duration" 920007,"PSAT_XBP_Extended_PAN_ID_hi"
(There should be more than 1000 lines in total of this 8 CSV files).
So what should I do now?