android如何在我的应用程序中获取第一行CSV文件?

时间:2014-04-05 05:10:31

标签: java android csv

我正在开发测验应用程序,其中我从CSV文件中获取所有问题。我从该文件中获取所有数据。但是当设置data.it时只设置csv file.can的最后一行。有人帮我吗?

这是我的代码: 公共类EssentialQuiz扩展了Activity {

private ArrayList<String> questionList = new ArrayList<String>();
private ArrayList<String> option1list = new ArrayList<String>();
private ArrayList<String> option2list = new ArrayList<String>();
private ArrayList<String> option3list = new ArrayList<String>();
private ArrayList<String> option4list = new ArrayList<String>();

Button btnanswer1, btnanswer2, btnanswer3, btnanswer4;
Button btnback, btnnext;
TextView txtQuestion;
QuestionDemo currentQ;
List<QuestionDemo> quesList;
int score = 0;
private int pos = 0;
private int count = 0;
private int rand[] = new int[10];
boolean flag = false;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.question);
    initwidget();
    btnback.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {

            // TODO Auto-generated method stub
            finish();
            overridePendingTransition(R.anim.trans_right_in,
                    R.anim.trans_right_out);
        }
    });
    List<String[]> list = new ArrayList<String[]>();
    String next[] = {};
    try {
        InputStreamReader csvStreamReader = new InputStreamReader(
                EssentialQuiz.this.getAssets().open(
                        "essentialsfinalglossaryquiz.csv"));
        CSVReader reader = new CSVReader(csvStreamReader);
        for (;;) {
            next = reader.readNext();
            if (next != null) {
                list.add(next);
            } else {
                break;
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    for (int i = 0; i < list.size(); i++) {
        questionList.add(list.get(i)[1]);
        option1list.add(list.get(i)[2]);
        option2list.add(list.get(i)[3]);
        option3list.add(list.get(i)[4]);
        option4list.add(list.get(i)[5]);

        System.out.println("Row::" + list.get(i)[1]);
        txtQuestion.setText(list.get(i)[1]);
        btnanswer1.setText(list.get(i)[2]);
        btnanswer2.setText(list.get(i)[3]);
        btnanswer3.setText(list.get(i)[4]);
        btnanswer4.setText(list.get(i)[5]);

        System.out.println("Row::" + list.get(i)[2]);
    }

0 个答案:

没有答案