I have a file with different questions and I need to read them one after another when the user clicks the “Next Button”. However, I can only read the first line and the following one and after that one the layout remains the same and doesn’t work. I will appreciate some help in order to read total questions. Here is part of my code:
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;
}
Here is the next button:
bNext.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
questions.Next();
questions = new Questions();
questions.Next();
currentQuestion();
}
});
The issue is that you are resetting the
questionsobject so it will get only the first line..Here:
You should have:
I hope it helps.