Reputation: 259
Hi guys am building a quiz app for android. In order to do this, i made a simple app consisting of three activities. The three activities are first, second and third question respectively with their answers. In each activity i have two buttons; next and previous, each button points to the other activity via intent object. From what i have done so far, i have achieved partially what i had in mind. Now my question is this:
is it possible to build such app without making each activity one question as i have done? Is there another way to build this kind of app? Is it possible to put all questions and their answers in one activity like a cardlayout in java?
Upvotes: 0
Views: 253
Reputation: 5308
Yes, definitely. There are many ways actually.
One of them, probably the easiest, would be to have an ArrayList<String>
for questions, another ArrayList<ArrayList<String>>
for the different possibles answers to questions, and then a third ArrayList<int>
to store the index of the chosen answer by the user.
When clicking Next and Previous, instead of launching a new Activity, you can keep track of which question you're currently showing and update the TextViews for questions and RadioButtons for answers accordingly.
Upvotes: 1