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 に答える