0

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 :

  1. How can I displaying all the values of my 8 csv files into 8 different activities?

  2. 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?

1 Answers1

0

It would help to have access to the CSV files so we can see the raw data.

In any event, I would reocmmend you check out this project. It is an open source project library that helps android beginners. It has a number of CSV utilities as well as a SOAP class for handling webservices that I have used in one of my big applications. It works quite well.

https://code.google.com/p/alternate-java-bridge-library/

BriCo84
  • 881
  • 1
  • 8
  • 10
  • For your information, it looks like the following picture, What I need is to display 2 rows ( Id , Parameter name ) and many rows. http://i.stack.imgur.com/vcg3M.png This image shows the least memory CSV file I had compared to other CSV files which maybe had more than 300 rows in one of it. – user2228829 May 21 '13 at 16:12
  • 1 of the question that I really want to know is that, For all those CSV reader codes on the websites, is it directly put into the main.java ( which corresponds to main.xml in eclipse when we created an android app project ) or rather, we create a new classes.java and put the code inside , then called it back in the main.java? – user2228829 May 21 '13 at 16:15