I have a constructor class object here:
public class Question {
public String question;
public boolean correctAnswer;
public Question(String question, boolean correctAnswer)
{
this.question = question;
this.correctAnswer = correctAnswer;
}
}
In my MainActivity I am creating questions and storing them in a List.
Then i want to make an f/else statement on button click so that when a user clicks button and the questions boolean type matches the if statement it is prompted to another question. The problem is I dont know how to get the questions boolean type.
public class MainActivity extends ActionBarActivity {
Button mYes;
Button mNo;
TextView mQuestion;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final int[] count = {0};
mYes = (Button)findViewById(R.id.button2);
mNo = (Button)findViewById(R.id.button);
mQuestion = (TextView)findViewById(R.id.textView);
//Creating question
final Question first = new Question("Do i understand this code?", false);
final Question second = new Question("kas tas?", true);
//question list
final ArrayList<Question> questions = new ArrayList<Question>();
//adding question
questions.add(first);
questions.add(second);
//show the question.
mQuestion.setText(questions.get(0).question);
mYes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if () {
count[0]++;
mQuestion.setText(questions.get((count[0]) % questions.size()).question);
} else {
finish();
}
}
});
I can get one Questions boolean type by writing first.correctAnswer. However I need all of the questions. Should I count all the questions with a for statement? If so how do I extrect the boolean type from that?
Aucun commentaire:
Enregistrer un commentaire