0

我有一个包含不同问题的文件,当用户单击“下一步按钮”时,我需要一个接一个地阅读它们。但是,我只能阅读第一行和下一行,之后的布局保持不变并且不起作用。为了阅读全部问题,我将不胜感激。这是我的代码的一部分:

public class Questions {
int i = 0;
int questionCount = 0;
int category;
String question;
int questionNumber=1;

void currentQuestion(Context context, int cat) {
    category = cat;



    String questionFile = "";



        questionFile = "VerbalSup1.txt";
        questionCount = 25;





    Log.i("Question", questionFile + ": " + questionCount);
    try {
        InputStream is = context.getAssets().open(questionFile);
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        // Skips lines
        for (i = 0; i< questionNumber; i++) {
            reader.readLine();

        }
        question = reader.readLine();


    } catch (IOException e) {
        e.printStackTrace();
    }


}
void Next(){
    questionNumber=questionNumber + 1;
}

这是下一个按钮:

bNext.setOnClickListener(new View.OnClickListener(){
            @Override

                public void onClick(View v) {
                    questions.Next();
                     questions = new Questions();
                     questions.Next();
                     currentQuestion();


            }


        });
4

1 回答 1

0

问题是您正在重置questions对象,因此它只会获得第一行。这里:

questions.Next();
questions = new Questions(); // this is wrong as the counts will be reset to defaults
questions.Next();
currentQuestion();

你应该有:

questions.Next();       
currentQuestion();
currentQuestion();

我希望它有所帮助。

于 2013-01-27T20:51:23.237 回答